Ask Your Question
0

How to read 10 bit tiff satellite image in opencv?

asked 2016-10-21 01:23:50 -0600

Madalasa gravatar image

updated 2016-10-21 03:57:19 -0600

berak gravatar image

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.

edit retag flag offensive close merge delete

Comments

you can use Mat Input= imread("10-BitFilename.tiff",IMREAD_ANYDEPTH);

Balaji R gravatar imageBalaji R ( 2016-10-21 01:36:45 -0600 )edit

The image pixels are not reading..

Madalasa gravatar imageMadalasa ( 2016-10-21 02:13:54 -0600 )edit

Show us your code and the error what you are getting!

Balaji R gravatar imageBalaji R ( 2016-10-21 02:49:59 -0600 )edit

10 bits will never fit into a byte, so Vec3b is the wrong type.

please check image.type() after loading, and report back.

berak gravatar imageberak ( 2016-10-21 03:59:56 -0600 )edit

This is not the complete code,Part of it...

Madalasa gravatar imageMadalasa ( 2016-10-21 04:01:26 -0600 )edit

also, please avoid per-pixel loops, slow and error prone.

what do you need the max for ?

berak gravatar imageberak ( 2016-10-21 04:05:34 -0600 )edit

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.

Madalasa gravatar imageMadalasa ( 2016-10-21 04:09:47 -0600 )edit
  • what is image.type() after loading ? you have to use exactly that type, if you need to traverse it
  • you must not code loops with opencv, please repeat 10 times. there is always something better already builtin. so what are your "operations" ? we can help you to findsomething better/faster/not-crashing.
berak gravatar imageberak ( 2016-10-21 04:16:38 -0600 )edit

Image 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

Madalasa gravatar imageMadalasa ( 2016-10-21 04:21:54 -0600 )edit

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.

berak gravatar imageberak ( 2016-10-21 04:30:58 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-10-21 04:30:21 -0600

kbarni gravatar image

The OpenCV tiff handling is quite basic (compared to what you can store in a TIFF file) - however normally it should be able to read 16 bit TIFF files.

Anyway, if you are having problems with the imread function, you better use libtiff to handle these images. It can handle any bit depth, any number of channels and any kind of data.

I already wrote a post about reading TIFF files with Libtiff and Opencv: http://answers.opencv.org/question/86...

edit flag offensive delete link more

Comments

How to read .img files

Madalasa gravatar imageMadalasa ( 2016-10-21 04:39:21 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-21 01:23:50 -0600

Seen: 3,294 times

Last updated: Oct 21 '16