How to save the proceesed image in the same size as input image

Hi,
I need to save the proceesed image in the same size (width and height) as the input image. I tried below script, but it still saves teh image in the smaller size than the input same.
width=2472;
height=2062;
set(gcf,'position',[x0,y0,width,height])

댓글 수: 3

I just pasted only the part of my code which is dealing the image size.
And I need to save my image without any axis. For this I am using axis off command

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

 채택된 답변

Matt J
Matt J 2025년 5월 3일
outputImage=imresize(outputImage,OutputSize=size(inputImage));
imwrite(outputImage , filename);

댓글 수: 6

This works perfectly in terms of preserving teh size. However my image looks completely different if I use imagesc () instead of imshow ()
Below is my complete code
II= imread("Input Image.jpeg");
II = rgb2gray(II);
II = imgradient(II);
figure ()
imshow(Gmag);
Unrecognized function or variable 'Gmag'.
colormap("gray");
axis off
outputImage=imresize(Gmag,OutputSize=size(II));
imshow(outputImage)
axis off
imwrite(outputImage , 'output.png');
Matt J
Matt J 2025년 5월 3일
편집: Matt J 2025년 5월 3일
Your code produces an error, as shown in the Run output above.
Ah, sorry.. Below is teh corrected done
II= imread("Input Image.jpeg");
II = rgb2gray(II);
[Gmag,Gdir] = imgradient(II);
figure ()
imshow(Gmag);
colormap("gray");
axis off
outputImage=imresize(Gmag,OutputSize=size(II));
imshow(outputImage)
axis off
imwrite(outputImage , 'output.png');
The below command solved the issue! Now, I am getting teh desired result.
imwrite( ind2rgb(im2uint8(mat2gray(Gmag)), gray(256)), 'output.png')
You could do it more simply like this:
outputImage = mat2gray(GMag); % Convert to gray scale image in the range 0-1.
imwrite(outputImage, 'output.png'); % Will save as PNG in the range 0-255.
No need for calling im2uint8(), and ind2rgb(), and gray(), unless for some reason you wanted your grayscale image to be a true color RGB image (but still appearing as grayscale).
This is good!. Thanks

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 White에 대해 자세히 알아보기

질문:

2025년 5월 3일

댓글:

2025년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by