画像回転後も回転前と同じ画像サイズにするにはどうしたらよいですか
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
1280×960の画像を回転させ、画像表示しその画像を保存するプログラムをつくりました。
画像サイズを変えたくないのですが、保存した画像が1334×1000になる為、
サイズ変更して画像を保存するようにしました。
結果、1281×961のファイルサイズになり元の画像サイズに戻りません。
どすればよいでしょうか
以下ソースコードです
% 画像選択
file = uigetfile('*.jpg');
% 画像読み込み
img = imread(file);
% 拡張子の置き換え
name = replace(file,'.','_');
% 180度ずつ360度まで回す
for i= 1:2
angle = 180*i;
figure();
% ファイル名
str = [name,'_',num2str(i)];
name_jpg = join(str);
% looseは中心ずれない、cropはズレる
imgr_loose = imrotate(img,angle,'crop');
%サイズ変更トライ(1280/1334)
imgr_size = imresize(imgr_loose,0.95952023);
% 余白なくして表示
imshow(imgr_size,'Border','tight');
saveas(gcf,name_jpg,'jpg');
close(gcf)
end
0 commentaires
Réponses (1)
Hernia Baby
le 5 Oct 2022
ついでにサイズ変更の部分も行と列に指定しました。
file = 'ngc6543a.jpg';
img = imread(file);
numrows = height(img);
numcols = width(img);
% 拡張子の置き換え
name = replace(file,'.','_');
% 180度ずつ360度まで回す
for i= 1:2
angle = 180*i;
figure();
% ファイル名
str = [name,'_',num2str(i)];
name_jpg = join(str);
% looseは中心ずれない、cropはズレる
imgr_loose = imrotate(img,angle,'crop');
%サイズ変更トライ(1280/1334) -> 行と列でサイズ変更
imgr_size = imresize(imgr_loose,[numrows numcols]);
% 余白なくして表示
imshow(imgr_size,'Border','tight');
% 書き換えたもの
% saveas(gcf,name_jpg,'jpg');
% close(gcf)
imwrite(imgr_size,[name_jpg,'.jpg']);
end
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!