Ask Your Question
0

save an image between 0 and 1

asked 2016-09-21 02:05:34 -0600

Hi,

I have a problem to save an image with pixel value between 0 and 1. When i save the pixel value in a txt file to check, i have the right value (0.023, 0.15 .....). But when i save this image to an image format, i can't get the see those values. I use imageJ to visualize the image and i test jpeg, png tif and bmp image formats.

What did i have miss?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-09-21 02:11:14 -0600

berak gravatar image

updated 2016-09-21 02:20:03 -0600

imwrite() can only save float images in ".exr" or ".hdr" format, and that only, if you built in suppport for that (WITH_OPENEXR).

if you want to save it as png or jpg, you will need to convert it to uchar first:

Mat floatImg = ...
Mat ucharImg;
floatImg.convertTo(ucharImg, CV_8U, 255.0);
imwrite("my.png", ucharImg);

alternatively, you can use the FileStorage, to save your img to yml (text):

 FileStorage fs("my.yml", 1);
 fs << "some_name" << image;  
 fs.release();
edit flag offensive delete link more

Comments

1

Well that work but how can i visualize the yml format. i mean like a normal image?

abenchaaben gravatar imageabenchaaben ( 2016-09-21 02:19:59 -0600 )edit
1

hmm, not possible outside opencv, unfortunately.

rather convert to uchar, and save as png, then.

berak gravatar imageberak ( 2016-09-21 02:23:51 -0600 )edit

Thank you for the help, but i want to visualize the floating image. I will keep serach for a solution. thank you again.

abenchaaben gravatar imageabenchaaben ( 2016-09-21 02:35:45 -0600 )edit

It is still the same image, basically converting it to uchar means you multiply it by a specific factor and visualise that. But the relative differences between pixels will still remain the same, only the base on which they are calculated is changed.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-22 06:31:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-21 02:05:34 -0600

Seen: 2,942 times

Last updated: Sep 21 '16