'How to imagesc display the image size to keep the size of the original matrix
data is a 512-by-512 matrix, visualized by imagesc, but the original 512-by-512 size cannot be saved, and the image size can only be saved as 800-by-800 by setting the following.
data = rand(512,512);
x = [0 0];
y = [512 512];
figure('position',[200,200,512,512]);
% image(log10(data(1:64,1:64)),'CDataMapping','scaled');
% figure;
imagesc(x,y,log10(data));
axis image;
axis off
axis equal
axis square
truesize([512 512])
% set(gca,'XTick',[])
% set(gca,'YTick',[])
set (gcf,'Position',[100,100,512,512]);
% truesize(fig,[512 512]);
set(gca,'Position',[0 0 1 1])
axis normal;
saveas(gca,strcat('tumor','.jpg'))
print -djpeg99 'foo.jpg'
Solution 1:[1]
imwrite uses the data you input as the pixel values to generate an image of the specified size.
This is an example of a 512-by-512 grayscale image:
data = rand(512, 512);
imwrite(data, 'foo.jpg');
If you want to produce a colour image, you need to input a 3-channel matrix, for example imwrite(rand(512, 512, 3), 'bar.jpg').
The (colour) encoding is otherwise specified in the documentation.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | magnesium |
