MATLAB Answers

Delete part of an image

3 views (last 30 days)
Hi, explain below what I want to do to see if anyone would know how to fix it.
I start with an image like the following:
IMG_0251.JPG
Now I make two circles, one with a smaller radius than the other, of which I know both its center and radius. They're not concentric but they never intersect
IMG_0253.PNG
And finally what I want to achieve is that all the points that are outside the major circle as well as inside the minor circle become black
IMG_0254.PNG

  0 Comments

Sign in to comment.

Accepted Answer

Matt J
Matt J on 16 Jan 2020
Edited: Matt J on 16 Jan 2020
[m,n]=size(oldImage);
x=(1:n);
y=(1:m).';
mask = (x-innerCenterX).^2+(y-innerCenterY).^2>=innerRadius^2 & ...
(x-outerCenterX).^2+(y-outerCenterY).^2<=outerRadius^2 ;
newImage=oldImage.*mask;

  3 Comments

Alajendro Fernández
Alajendro Fernández on 16 Jan 2020
I have an error using that, because oldImage is Integer and mask is logical
"Error using .*
Integers can only be combined with integers of the same class, or scalar doubles."
Matt J
Matt J on 16 Jan 2020
Appropriate type conversions will fix it,
newImage=uint16( double(oldImage).*mask );
Alajendro Fernández
Alajendro Fernández on 16 Jan 2020
Thank you so much, it works!

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2019b