MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Sivakumaran Chandrasekaran
on 11 Sep 2012

I have drawn a star on a image and i want to crop that star region alone. How to do it?

Answer by Image Analyst
on 18 Jan 2013

Accepted answer

Use max() and min() to find the extremes of the coordinates you drew. Then you can create a box and use imcrop(). You know that cropping gives you a matrix which is a rectangular shape, right?

Answer by Walter Roberson
on 18 Jan 2013

poly2mask() and use the resulting mask to extract pixels from the image. You will probably also want to calculate the bounding box of the mask and create a rectangular area that size to store the extracted pixels in (as it is not possible to have a matrix which is an irregular shape.)

Image Analyst
on 18 Jan 2013

Just noticed this was 4 months old. I have no idea how both of us could have missed it back then.

Walter Roberson
on 18 Jan 2013

I saw it back then but I was busy and I figured someone else would answer.

Sivakumaran Chandrasekaran
on 18 Jan 2013

Even though it is late, I thank you both Image Analyst and Walter.

## 2 Comments

## Andrei Bobrov

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/47836#comment_98661

use function

cropfromImage Processing Toolbox## KIRAN kumar

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/47836#comment_123340

select the area first by selecting the star by defining it then perform corp.u can use image segmentation process for this