Cropping the image with boundary condition

1 回表示 (過去 30 日間)
prashant singh
prashant singh 2017 年 12 月 2 日
回答済み: Image Analyst 2017 年 12 月 5 日
I am tracking an object in an image. Once the object is located i am cropping the image of size 120*60 using
crop1=imcrop(image,[x1-30,y1-50,60,120])
The issue is when its near the boundary, the cropped image size get reduced and i am shorter(y axis) or thinner (x axis)cropped images.

採用された回答

Image Analyst
Image Analyst 2017 年 12 月 5 日
If the image is smaller because some part of the cropped image would lie off the original image, then you can paste the smaller part onto a matrix of zeros that is the full size. See my copy and paste demo.

その他の回答 (1 件)

Elizabeth Reese
Elizabeth Reese 2017 年 12 月 5 日
If any of these values are outside of the range of pixels that the image actually inhabits, than the resulting image will looked more cropped than expected. So if the xmin or ymin are negative, then the resulting image will not be the whole 60x120 size.
I recommend using min and max to keep the ranges within the the boundary of the original image.

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by