Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
271 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...