Saved Matrix as Image does not give me the right pixels

조회 수: 2 (최근 30일)
Hakan Östen
Hakan Östen 2020년 5월 27일
댓글: Subhadeep Koley 2020년 5월 28일
Hi there,
currently I am trying to save a (100 x 100) matrix in one .tif image.
When opening this image, it occurs that it has 1200 x 900 pixels eventhough it should be 100 x 100.
Nsub = 100
Q = reshape(Isub(:,:,is)(:,j),[Nsub,Nsub]); % Q has the size of 100 x 100.
% Output data as a figure
figure()
%set_x_axis = [ -Nsub Nsub];
%set_y_axis = set_x_axis
imagesc(Q);
newmap = contrast(Q); % Change into greyscale
colormap(newmap);
set(gca,'XTick',[], 'YTick', []);
save_in_folder = "C:/Users/TestImages";
file = sprintf("%s/%dmm/tif/%03d.tif", save_in_folder, List_of_foldernames(is),k);
saveas(imagesc(Q), file);
Has anyone an idea why?

답변 (1개)

Subhadeep Koley
Subhadeep Koley 2020년 5월 27일
Hakan, you are getting a 1200-by-900 image because you're saving the entire figure window in the tif file. If you only need to save the image, refer the code below,
nSub = 100;
% Creating a random image
img = rand(nSub);
% Visualize the image
figure
imagesc(img)
newMap = contrast(img);
colormap(newMap);
% Write the image and its associated colormap
imwrite(im2uint8(img), newMap, 'yourFile.tif')
  댓글 수: 4
Hakan Östen
Hakan Östen 2020년 5월 28일
편집: Hakan Östen 2020년 5월 28일
When Q is outputted as a figure in a popup, it works fine.
It seems that imwrite does not work properly. The image is stored empty. No information seems to get out.
Edited: I found the issue. The matrix did not have a scale of 0 255 pixels. I used
uint8(255*mat2gray(Q))
to fix it.
Thanks Subhadeep.
Subhadeep Koley
Subhadeep Koley 2020년 5월 28일
@ Hakan Östen You tried this?
imwrite(rescale(img, 0, 255), newMap, 'yourFile.tif')

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by