I usually use imcrop
to crop rectanguler image but i wat to create circular crop. How to do it?
I know there is another quetion about this, here the link:
MATLAB: how do I crop out a circle from an image
[xx,yy] = ndgrid((1:imageSize(1))-ci(1),(1:imageSize(2))-ci(2));
mask = (xx.^2 + yy.^2)<ci(3)^2;
and the result of imshow(mask)
is rectangle with white background
Cropping Circular region of interest around a point in MATLAB
error in roimaskcc
http://www.mathworks.com/matlabcentral/newsreader/view_thread/242489
[xx,yy]=ndgrid(1:size(X,1), 1:size(X,2));
CroppingMask= ( (xx-Xcenter).^2+(yy-Ycenter).^2<=Radius^2 );
X=X.*CroppingMask;
The result of imshow(CroppingMask)
is a rectangle with black background with small white circular at the center of the rectangle. When I run line 3 it shows an error.
Please help me, step by step because I'm a beginner.
Here is my image: https://www.dropbox.com/s/5plqzqgyb1ej6gh/patricia.jpg. It resolution is 480x640.
Crop the image. Double-click the left mouse button or right-click inside the boundary of the crop rectangle and select Crop Image from the context menu. Retrieve the coordinates of the crop rectangle. Right-click inside the boundary of the crop rectangle and select Copy Position from the context menu.
To extract a rectangular portion of an image, use the imcrop function. Using imcrop , you can specify the crop region interactively using the mouse or programmatically by specifying the size and position of the crop region.
Solution (1) works perfectly well. Here is a complete working example using your image.
I = imread('patricia.jpg');
imageSize = size(I);
ci = [250, 300, 100]; % center and radius of circle ([c_row, c_col, r])
[xx,yy] = ndgrid((1:imageSize(1))-ci(1),(1:imageSize(2))-ci(2));
mask = uint8((xx.^2 + yy.^2)<ci(3)^2);
croppedImage = uint8(zeros(size(I)));
croppedImage(:,:,1) = I(:,:,1).*mask;
croppedImage(:,:,2) = I(:,:,2).*mask;
croppedImage(:,:,3) = I(:,:,3).*mask;
imshow(croppedImage);
It produces the following image.
I hope this clarifies things. There is probably a better way of re-assembling the cropped image, but this was what I could come up with off the top of my head.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With