画像を下半分だけにしたい。
Show older comments
画像が720x960であるのですが画像を切り取って下半分だけにしたいです。
Accepted Answer
More Answers (1)
画像データのピクセル(行列)インデックスではなく空間座標を使う点や、双方のx,y座標が逆転する点に注意が必要です。
I = imread('画像ファイル名.jpg'); % 画像ファイルを読み込む
% I = uint8(zeros([960 720 3])); % 画像ファイルの代わりにカラーの画像データを準備
size(I)
center = (size(I,1) + 1) / 2; % 画像データ中央のy座標(空間座標)
half = size(I,1) / 2; % 画像データ高さの半分
I = imcrop(I, [1 center size(I,2) half]); % 画像を切り取って下半分だけにする
size(I)
imwrite(I,'画像ファイル名_下半分.png');
Categories
Find more on Image Preview and Device Configuration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!