How to read 10 bit tiff satellite image in opencv?
Maximum pixel value of the tiff image is 481. But it is showing maximum is 1.So how to read properly.
#include <opencv2/core/core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\nonfree\features2d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
Mat IMG(5620, 4894, CV_8UC3, Scalar(0, 0, 0));
int main()
{
/* Input Image of 4894*5620 size */
Mat image = imread("C:\\Users\\IIST\\Desktop\\Madi\\NRSC_OCT\\a.tif",IMREAD_ANYDEPTH);
//Mat image = imread("D:\\SC15M053\\PROGRAM AND OUTPUTS\\NRSC\\post_image\\53N07_cl.img", IMREAD_ANYDEPTH);
int ch = image.channels();
int R = image.rows;
int C = image.cols;
cout << "Channles : " << ch << endl << "Rows are : " << R << endl << "Cols are : " << C << endl;
int max = image.at<Vec3b>(0, 0)[0];;
//int max = image.at<Vec3b>(258, 519)[2];
for (int i = 0; i < R; i++)
{
for (int j = 0; j < C; j++)
{
if (max < image.at<Vec3b>(i, j)[0])
max = image.at<Vec3b>(i, j)[0];
}
}
cout << "Maximum value of band : " << max << endl;
cin.get();
return(0);
}
Exception: Unhandled exception at 0x000007FFFF05AEA8 in FirstOpencv2.exe: Microsoft C++ exception: cv::Exception at memory location 0x00000034A04EF4E0.
you can use Mat Input= imread("10-BitFilename.tiff",IMREAD_ANYDEPTH);
The image pixels are not reading..
Show us your code and the error what you are getting!
10 bits will never fit into a byte, so Vec3b is the wrong type.
please check image.type() after loading, and report back.
This is not the complete code,Part of it...
also, please avoid per-pixel loops, slow and error prone.
what do you need the max for ?
I need to perform some operations on the image, For every pixel... And what is the data type i have to use for "image.type". When i used int data type it gave output 2.
image.type()
after loading ? you have to use exactly that type, if you need to traverse itImage is in .img format. But Opencv is not reading properly, So i converted to tif format. Generally i have to do the segmentation, for each object i have to perform threshold operation. image.type() is 2. But my image is contains 3 channels. Max is using just to check the value. Not using in my program
type == 2 == CV_16U. so you got a single ushort channel there, neither int, nor Vec3b, and not 3 channels.
then, there is minMaxLoc to find min/max values in that.
please try to learn opencv's api, do not sidestep it.
Hey in ERDAS, ENVI,eCognition softwares image is showing that it is 3 bands image, i.e 3 channel.
I have to read all the intensity values,i.e 3 bands(R,G,B).So how to access it? Original image is ".img" format.