Matlab 中的圆形掩码
Circular mask in Matlab
我在 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;
好的,我明白了。
您的函数 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)
结果:
我在 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;
好的,我明白了。
您的函数 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)
结果: