Convert data on a TIFF image and save it

2 ビュー (過去 30 日間)
Haimon
Haimon 2014 年 4 月 5 日
コメント済み: Haimon 2014 年 4 月 11 日
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);
Haimon
Haimon 2014 年 4 月 11 日
Thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBlue についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by