When to use Double data type for an image in matlab?

53 views (last 30 days)
I am trying to find out focus score of an image for which i need to get both the mean and variance. i m getting some Values for both these parameters if i convert the image into data type double. But the image, after changing its data to double, appears like a few spots on the screen, nothing else. I could be wrong in judging it as loss of information of the image. So Please guide me..... i hope this data type conversion has no effect on the information content of the image and using it wont effect my end result to find focus score of the image.

Accepted Answer

Guillaume
Guillaume on 23 Jun 2015
How do you convert to double:
  • im2double(img) ?
  • just double(img) ?
  • double(img) / max(img(:)) ?
  • something else ?
In any case, no, you're not losing information. The issue is with how you display it. Try:
imshow(img, []);
  2 Comments
dv
dv on 24 Jun 2015
thank you for your reply. i am using --- img=double(imread('cell.jpg')); Could you plz elaborate that how imshow(img, []) is different from imshow(img), Both are displaying the same image (spots as i mentioned earlier). other than this what you are saying is that converting to double is just a display modification aiding us to calculate mean and variance for the image? please guide if i m getting wrong.. thank you
Guillaume
Guillaume on 24 Jun 2015
Walter has already explained most of the differences between a double image and a uint8 image. Converting to double is not just for display. Some matlab functions (e.g. conv2 do not work with integer).
The difference between imshow(img) and imshow(img, []) is that the former assumes the intensity range based on the image type. For uint8, it assumes that intensities are in the [0-255] range. For double, it assumes it is in the [0-1] range. Using [] tells imshow to use the min-max of the image instead.
So, when converting an image to double it is best to ensure that intensities are in the range [0-1]. im2double(img) will do the rescaling for you, so it's better to use it instead of just plain double(img).

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 24 Jun 2015
When you use img=double(imread('cell.jpg')); then the values you get will be the floating point versions of integers.
When you apply image() to a floating point array that is 3D then it assumes that the values are valid RGB values in the range 0 to 1, and will treat everything larger than 1 as if it was one.
When you apply image() to a floating point array that is 2D then it assumes that the values represent indices into the colormap, and will treat anything larger than the number of colormap entries as if it should be the last colormap entry. This does not apply to your immediately situation because .jpg files are never 2D, always 3D (the same does not appear to hold true for .jp2 files.)
If you want to convert a uint8 image (values 0 to 255) to a double image that will be recognized as representing the same colors, you should use im2double(), which will (generally) do double(TheData)./255 and so generally return values from 0 to 1 as expected by display() for a double RGB image.
double() vs uint8 and 2D vs 3D are important to display() to determine what the values represent.

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!