我在Matlab中创建了六个用于屏蔽的圆圈。掩模的内半径和外半径中的每一个都是不同的。这些掩模用于检测载玻片上的寄生虫。我有这个代码(其中一个面具),但我想在共享图像中圈出白色区域。我怎样才能做到这一点?或者有另一种方法来做共享图片的掩码? 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;
答案 0 :(得分:0)
好的,现在我明白了。
您的函数MidpointCircle仅创建圆的边框,而不是填充的整个圆。以下代码计算到中心的距离,并选择小于外半径且大于内半径的所有值:
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)
结果: