2015-06-02 82 views
-1

我在Matlab中創建了六個用於掩蔽的圓。每個蒙版的內外半徑都不相同。這些掩模用於檢測幻燈片上的寄生蟲。我有這個代碼(面具之一),但我想做白色區域以在共享圖像中圈出。我怎樣才能做到這一點?或有另一種方法來做掩碼共享圖片? MidpointCircle.mMatlab中的圓形掩模

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

回答

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) 

結果:

enter image description here

+0

謝謝。問題解決了。 – sunshine