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

26 次查看(过去 30 天)
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.
  1 个评论
Vaibhav
Vaibhav 2024-8-30
When you convert an image from 8-bit to double without proper scaling, the image might appear as a few spots because the values are not in the expected range (0.0 to 1.0) for display. This does not necessarily mean information is lost, but the visual representation changes. As far we know, the pixel values are typically scaled between 0.0 and 1.0, or they can represent a much broader range of values.
Mean and Variance: These statistics should remain consistent regardless of the data type, provided you handle the conversion correctly.
  • Mean: Represents the average pixel intensity.
  • Variance: Measures the spread of pixel intensities.
If you calculate the mean and variance after converting to double, the results will be in line with the data type's scale (e.g., a mean close to 0.5 if scaled to 0.0-1.0).
For calculations, what matters is the underlying numerical data, not how the image appears visually.

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2015-6-23
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 个评论
dv
dv 2015-6-24
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 2015-6-24
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).

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2015-6-24
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.

类别

Help CenterFile Exchange 中查找有关 Data Type Identification 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by