Circular mask in Matlab

我的梦境 提交于 2019-12-13 08:58:48

问题


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;


回答1:


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:



来源:https://stackoverflow.com/questions/30592110/circular-mask-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!