Saving a resized image while keeping the resized values

21 ビュー (過去 30 日間)
Alberto Acri
Alberto Acri 2023 年 1 月 2 日
編集済み: Matt J 2023 年 1 月 2 日
Hi! I want to save a resized image in .png format. The .png image I start from has size 656x875 pixels.
I used this code to resize the image so that it is 500x500 pixels and the code works.
imageArray = imread('figure_001.png');
figure();
axis equal
imshow(imageArray);
image8bit = rgb2gray(imageArray);
imagelogical = logical(image8bit);
figure();
axis equal
imshow(imagelogical);
resize_image = imresize(imagelogical, [500 500]);
name_figure = figure;
axis equal
imshow(resize_image);
The problem occurs when I save the resized image. I am using this code:
output = sprintf('figure.png');
fulldestination = fullfile(pwd, output);
saveas(name_figure, fulldestination)
however when I view the properties of the figure I get a size of 766x855 pixels. How come?

採用された回答

Matt J
Matt J 2023 年 1 月 2 日
編集済み: Matt J 2023 年 1 月 2 日
Because with saveas, you are saving a screenshot of the figure window, not an image composed from the pixel values of resize_image itself. Use imwrite instead,
imwrite(resize_image,fulldestination)

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by