Convert data on a TIFF image and save it

5 次查看(过去 30 天)
Hi,
I made some calculations regarding data I use for my research in image analysis.
Since I wanted to have an image that showed the variations of my variable, I transformed my data into values between 0-65535. I can not work with 0-255, because it is a very small range for what my original data is.
My problem is: I tried to create a grayscale image, and save it into a .tiff file. However not only I cannot obtain the file, but the image that MatLab is showing me does not have any variations. Is either all black or all white.
I'm sure my data is correct. I looked into the original variable, and everything is correct. I also looked into the variable that transforms those original data into values between 0-65535. I found several values ranging, primarily, between 10000 and 50000, so everything looks fine.
Does anyone knows how to convert N² data into an image of NxN size and show those variations? Also how to save it, .tiff file to be more specific?
My code up until now, regarding the problem:
% shows my grayscale image
figure;
image(tcrho); %tcrho is my variable, already in 0-65535 scale
colormap(gray(65536); %grayscale colormap
cbh = colorbar('location', 'SouthOutside'); %just location and name of my colorbar
set(cbh, 'Units', 'normal');
text(3.5, -1, 'Densidade crescente', 'Parent', cbh);
%save my image. I need to save several images - that explains the %04d.
rtc = sprintf('rho%04d.tiff',d);
imwrite(tcrho,gray(65536),rtc,'tiff')

采纳的回答

Image Analyst
Image Analyst 2014-4-5
What does
whos tcrho
show? I want to know if it's uint16 or double. By the way, you can't have a colormap with 65536 entries in it. Simply display your image like this:
imshow(tcrho, []);
and don't use a colormap at all.
  6 个评论
Image Analyst
Image Analyst 2014-4-10
Sorry - it turns out mat2gray scales between 0 and 1, not 0 and 255. So if you want a regular 8 bit image, you have to multiply by 255. So if you want a 16 bit image, you have to multiply by 65535.
imwrite(uint8(255*mat2gray(tcrho)), filename);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by