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

조회 수: 28 (최근 30일)
dv
dv 2015년 6월 23일
댓글: Vaibhav 2024년 8월 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