How to crop an image?
2 ビュー (過去 30 日間)
古いコメントを表示
Here I have some points, lets points=[x1,y1,x2,y2,x3,y3......xn,yn] these points are precalculated based on some mathematical calculation. Now I want to crop an image based on these points, i.e I want take the parts of the image thats are covered in these points. If any one have an idea help me! Thank you!
0 件のコメント
回答 (1 件)
Image Analyst
2014 年 4 月 28 日
What if they are not in a box? Images must be rectangular. If the x and y don't specify a rectangle, then you can use max(x), min(x), max(y), and min(y) to find the bounding box. Then use imcrop. If you want a polygon and not a rectangular crop, then you must mask instead of crop. You can use poly2mask() for that to get a binary image. Then multiply that by the image, or set the inverse of that in the image to zero (there's 2 ways).
out = in * uint8(binaryImage);
or
out = in;
out(binaryImage) = 0;
2 件のコメント
Image Analyst
2014 年 4 月 28 日
Glad it worked. Can you please mark the Answer as Accepted then? You can actually do both if you want -- you can mask then crop to the bounding box. It just depends on what you want to do. For image segmentation, usually masking is sufficient and cropping is not necessary unless you want to magnify the region of interest in the display just for visual curiosity or inspection.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!