Ask Your Question

how to process tiff image

asked 2013-03-12 08:10:42 -0500

lyw8120 gravatar image

Yes, opencv can easily to read iamge, but how to process it because its compress, and its data type.

I want to do a dft after import tiff image. but failed. showed that it should be CV_32FC1, CV_32FC2 etc.

That means opencv did not convert the data type to its own data type, right?

so how to solve this problem


edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-03-12 09:23:43 -0500

berak gravatar image

updated 2013-03-12 16:04:58 -0500

this will require a grayscale(1 channel) image, so we convert it to grayscale when loading:

Mat img = imread("my.tiff", CV_LOAD_IMAGE_GRAYSCALE);

since this is still uchar data (CV_8UC1) you 'll have to convert it to floating type:

Mat ff_in;
img.convertTo( ff_in, CV_32FC1, 1.0/255.0 );  // [0..1] range

run the dft:

Mat ff_out;
dft( ff_in, ff_out );

then, convert it back:

Mat ff_gray;
ff_out.convertTo( ff_gray, CV_8UC1, 255.0 );
edit flag offensive delete link more


Thanks a lot, that is what I need. the first big problem is to convert data type from one library to another one for a new man.

lyw8120 gravatar imagelyw8120 ( 2013-03-12 17:32:39 -0500 )edit

answered 2013-03-12 08:14:30 -0500

It is quite easy, just use the C++ functionalit which will do the type conversion for you.

Mat img = imread(location);
edit flag offensive delete link more

Question Tools


Asked: 2013-03-12 08:10:42 -0500

Seen: 7,931 times

Last updated: Apr 26 '13