Matlab中的圆形蒙版 [英] Circular mask in Matlab

查看:216
本文介绍了Matlab中的圆形蒙版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Matlab中创建了六个用于遮罩的圆.遮罩的内半径和外半径各不相同.这些面罩用于检测载玻片上的寄生虫.我有这段代码(其中一个蒙版),但是我想在两者之间做白色区域以在共享图像中圈出它.我怎样才能做到这一点?或还有另一种方法来遮罩该共享的图片? MidpointCircle.m

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;

推荐答案

好的,现在我明白了.

您的函数MidpointCircle仅创建一个圆的边界,而不创建整个圆.以下代码计算到中心的距离,并选择所有小于外部半径且大于内部半径的值:

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)

结果:

这篇关于Matlab中的圆形蒙版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆