フィルターのクリア

Problem with saveas imshow and imwrite

12 ビュー (過去 30 日間)
Efstathios Kontolatis
Efstathios Kontolatis 2016 年 9 月 19 日
コメント済み: Image Analyst 2016 年 9 月 29 日
Hi all,
I have a problem trying to save my images. I have a 512x512 tif figure. When I use this code(Image is my 512x512 uint8 image)
f = figure;set(f,'Visible','off');
imshow(Image,[]);
imwrite(Image,sprintf('image-background%d.tif',i));
the image that is saved is different from that shown which is logical because I ask the code to save the Image not the figure. However the saved image is 512x512. If I use this code
f = figure;set(f,'Visible','off');
imshow(Image,[]);
saveas(f,sprintf('image-background%d.tif',i));
the image is what I want but the dimensions are 900x1200x3. I want to combine the two solutions in a way that I will get the f figure as a 512x512 tif image. Is there a way to do so?
  8 件のコメント
Adam
Adam 2016 年 9 月 29 日
There is a builtin function called 'image'. Matlab will distinguish 'Image' separately from 'image' so your variable will not actually hide the function of that name as it would if you named it 'image', but you should still not name variables the same as functions, irrespective of capitalisation. Matlab is very variable on when it takes capitalisation into account and when it doesn't!
Image Analyst
Image Analyst 2016 年 9 月 29 日
If you use [], MATLAB scales your image to put the min at 0 and the max at 255.
If you don't use that, MATLAB will assume your floating point variable is in the range of 0-1. Anything less than or equal to 0 will show up as black, and anything 1 or more will show up as white, and things in the 0-1 range will be in gray scale.
If you have floating point numbers in the range 0-255 or whatever, then chances are lots of your pixels are above 1 or below 0 and so your image appears binary even though it is not.
If you have a floating point image and want to retain all the values, save it into a .mat file with save().
If you want to save it as an integer copy so that you can use a standard image format like .PNG, then use mat2gray() to scale it.
image8bit = uint8(255 * mat2gray(floatingPointImage));
imwrite('whatever.PNG', image8bit);

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

回答 (1 件)

Image Analyst
Image Analyst 2016 年 9 月 19 日
imwrite() saves the image variable, while saveas() saves a screenshot, which may not be the same number of pixels as the underlying image.
  1 件のコメント
Efstathios Kontolatis
Efstathios Kontolatis 2016 年 9 月 20 日
Please look above at the wuestion I've just edited it.

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

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by