double data type in image processing

조회 수: 38 (최근 30일)
stari
stari 2021년 11월 3일
댓글: stari 2021년 11월 10일
X=imread('cameraman.tif); %read the cameraman image
imshow(X)
X=doube(X);
imshow(X)
I wonder why that second picture is blank when i put the command 'double(X)'

채택된 답변

yanqi liu
yanqi liu 2021년 11월 3일
sir,because trait image as uint8 data,0~255
so,double data should set the pixel range,default is []
X=imread('cameraman.tif'); %read the cameraman image
figure; imshow(X)
X=double(X);
figure;imshow(X)
figure;imshow(mat2gray(X))
figure;imshow(X, [])
figure;imshow(X, [20 150])
  댓글 수: 3
DGM
DGM 2021년 11월 3일
All of this can be avoided by simply using im2double() instead of double().
stari
stari 2021년 11월 5일
im2double..! Thanks for your help:)

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

KSSV
KSSV 2021년 11월 3일
Try to read colormap alsp. Any ways for the present image it is empty.
[I,cmap] = imread('cameraman.tif');
imshow(double(I),cmap)
imshow(double(I),[]) % also can be used

Constantino Carlos Reyes-Aldasoro
Another easy way around this is to divide the doubles by 255
X=imread('cameraman.tif'); %read the cameraman image
X=double(X);
imshow(X/255)
  댓글 수: 2
stari
stari 2021년 11월 3일
I think i didn't know about the unit8 and double. Thanks for your help!
Image Analyst
Image Analyst 2021년 11월 3일
There is no unit8() though there is a uint8().

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2021년 11월 3일
Let me try to explain it.
If the image is uint8 it expects the image to be in the range 0-255.
If the image is uint16 it expects the image to be in the range 0-65535.
If the image is double, imshow() assumes the image will be in the range 0-1. Anything below 0 will show up as black. Anything more than 1, like 100 or 255, will show up as white. Your image was all more than 1 so that's why it showed up as all white. There are two "fixes" for this:
The first is to scale your data by dividing it by 255, 65535, or the max value of your image to scale it to the 0-1 range. Then you can use imshow(X) to see the image without clipping to black or white. X is a bad name for an image by the way. You can also change/scale your data by calling one of these:
X2 = im2double(X) ;
X2 = rescale(X, 0, 1);
X2 = gray2mat(X);
imshow(X2);
Of course you can also stick the scaled/changed data back into your original array X if you want.
The other way doesn't require you to change or scale your data, you just use [] in imshow:
imshow(X, []);
This is the way I do it because I usually don't like to change the range of my data - sometimes it causes confusion later. What this does is to take the min of your data and make it black, and the max of your data and make it white. Like if the data went from 40 to 190, 40 would show up as black (0) and 190 as white (255). You can put numbers inside the [] to specify the output range and you can also specify the input range so basically you can do any kind of "window and leveling" (as they call it in the medical field) that you want. In other words, you can have whatever value you want for the min show up as whatever output brightness you want. Same for the max/brightest value. And values in between are scaled linearly in brightness.
Does that explain it well enough? If not, ask questions, especially with specific numbers, and I'll answer them.
  댓글 수: 3
Image Analyst
Image Analyst 2021년 11월 5일
OK, you can accept only one answer so pick the one that gave the best solution or explained your question best. If any of the other answers were also helpful you can "Vote" for them by clicking on the icon to award the posters reputation points.
stari
stari 2021년 11월 10일
Okay!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by