Circular mask in Matlab
Asked Answered
B

1

-1

I create six circle for masking in Matlab. Each of mask's inner and outer radiuses are different. These masks is used to detect parasites on the slide. I have this code (one of the masks) but I want to do white area between to circle that in shared image. How can I do that? or Have another way to do mask that shared picture? MidpointCircle.m

resize_factor = 1;
inner_rad = 15*4/resize_factor;
outer_rad = 20*4/resize_factor;

ec_2 = floor(0.5*(outer_rad+inner_rad)*2*pi);

center = outer_rad+2; 
mask1_size = center*2;

circleimg = zeros(mask1_size,mask1_size);
circleimg = MidpointCircle(circleimg, outer_rad, center, center, 1);
circleimg = MidpointCircle(circleimg, inner_rad, center, center, 1);
mask1 = circleimg;

enter image description here

Brainwashing answered 2/6, 2015 at 9:23 Comment(0)
A
0

Ok, now I get it.

Your function MidpointCircle only creates the borders of a circle, not the whole circle filled. The following code calculates the distance to the center and selects all values that are smaller than the outer and bigger than the inner radius:

clear all;

resize_factor = 1;
inner_rad = 15*4/resize_factor;
outer_rad = 20*4/resize_factor;

ec_2 = floor(0.5*(outer_rad+inner_rad)*2*pi);

center = outer_rad+2; 
mask1_size = center*2;

[x,y] = meshgrid(1:mask1_size,1:mask1_size);

distance = (x-center).^2+(y-center).^2;
mask = distance<outer_rad^2 & distance>inner_rad^2;

figure(1);
imshow(mask)

Result:

enter image description here

Apia answered 2/6, 2015 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.