How to crop image by specific size and location ?

21 ビュー (過去 30 日間)
Jenifer NG
Jenifer NG 2022 年 5 月 13 日
コメント済み: Jenifer NG 2022 年 5 月 13 日
Dear Matlab experts,
I want to crop an image by specific size (64x64) and location. but the result is not correct
Could anyone help me ?
My step is:
  1. Detect the centroid of image
  2. Cropimage
I=imread('2_mask.png')
I2 = imcrop(I,[739.72-32 406.02+32 739.72+32 406.02-32]);
The problem is: the cropped image (I2) is 375x393 [pixel] not 64x64 [Pixel]. The area is bigger than what i expext
This is Cropped image I2 but the size is 375x393 [pixel]
Thanks
Han

採用された回答

DGM
DGM 2022 年 5 月 13 日
編集済み: DGM 2022 年 5 月 13 日
The rect parameter given to imcrop is [xoffset yoffset xwidth ywidth]
I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/996600/2_mask.png');
I2 = imcrop(I,[739.72-32 406.02-32 64 64]);
imshow(I2)
... although you may find out that you have to subtract 1px from the widths if you actually want a specific output size. This behavior is explained in the help for imcrop().
I2 = imcrop(I,[739.72-32 406.02-32 63 63]); % this will be 64x64 instead of 65x65
  1 件のコメント
Jenifer NG
Jenifer NG 2022 年 5 月 13 日
It is working fine, Thank so much for your detail explaination

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by