# How can I perform region growing with two seed points?

29 ビュー (過去 30 日間)
Cretu Ioana 2020 年 3 月 15 日

Hi everyone! I have some images of the carotid artery, and I need to segment the image to obtain the outer wall and the plaque region. I used a function posted here (region growing from one seed point), and I tried to modify it. I want the function to have two seeded points, but my function doesn't work. Can you please give me some suggestion?
This is for my school project.
function J=RG2incerc(I,x,y,x2,y2,reg_maxdist1,reg_maxdist2)
% This function performs "region growing" in an image from a specified
% seedpoint (x,y)
%
% J = regiongrowing(I,x,y,t)
%
% I : input image
% J : logical output image of region
% x,y : the position of the seedpoint (if not given uses function getpts)
% t : maximum intensity distance (defaults to 0.2)
%
% The region is iteratively grown by comparing all unallocated neighbouring pixels to the region.
% The difference between a pixel's intensity value and the region's mean,
% is used as a measure of similarity. The pixel with the smallest difference
% measured this way is allocated to the respective region.
% This process stops when the intensity difference between region mean and
% new pixel become larger than a certain treshold (t)
%
% Example:
% I = im2double(imread('medtest.png'));
% x=198; y=359;
% J = regiongrowing(I,x,y,0.2);
% figure, imshow(I+J);
%
% Author: D. Kroon, University of Twente
if(exist('reg_maxdist1','var')==0), reg_maxdist1=0.2; end
if(exist('y','var')==0), figure, imshow(I,[]); [y1,x1]=getpts; y=round(y(1)); x=round(x(1)); end
J = zeros(size(I)); % Output
J2=zeros(size(I));
Isizes = size(I); % Dimensions of input image
reg_mean = I(x,y); % The mean of the segmented region
reg_mean2=I(x2,y2);
reg_size = 1; % Number of pixels in region
reg_size2=1;
% Free memory to store neighbours of the (segmented) region
neg_free = 10000; neg_pos=0; neg_free2=10000; neg_pos2=0;
neg_list = zeros(neg_free,3); neg_list2 = zeros(neg_free2,3);
pixdist=0; % Distance of the region newest pixel to the regio mean
pixdist2=0;
% Neighbor locations (footprint)
neigb=[-1 0; 1 0; 0 -1;0 1];
neigb2=[-1 0; 1 0; 0 -1;0 1];
% Start regiogrowing until distance between regio and posible new pixels become
% higher than a certain treshold
while(pixdist<reg_maxdist1&&reg_size<numel(I))
% Add new neighbors pixels
for j=1:4,
% Calculate the neighbour coordinate
xn = x +neigb(j,1); yn = y +neigb(j,2);
% Check if neighbour is inside or outside the image
ins=(xn>=1)&&(yn>=1)&&(xn<=Isizes(1))&&(yn<=Isizes(2));
% Add neighbor if inside and not already part of the segmented area
if(ins&&(J(xn,yn)==0))
neg_pos = neg_pos+1;
neg_list(neg_pos,:) = [xn yn I(xn,yn)]; J(xn,yn)=1;
end
end
% Add a new block of free memory
if(neg_pos+10>neg_free), neg_free=neg_free+10000; neg_list((neg_pos+1):neg_free,:)=0; end
% Add pixel with intensity nearest to the mean of the region, to the region
dist = abs(neg_list(1:neg_pos,3)-reg_mean);
[pixdist, index] = min(dist);
J(x,y)=2; reg_size=reg_size+1;
% Calculate the new mean of the region
reg_mean= (reg_mean*reg_size + neg_list(index,3))/(reg_size+1);
% Save the x and y coordinates of the pixel (for the neighbour add proccess)
x = neg_list(index,1); y = neg_list(index,2);
% Remove the pixel from the neighbour (check) list
neg_list(index,:)=neg_list(neg_pos,:); neg_pos=neg_pos-1;
end
J=J>1;
while(pixdist2<reg_maxdist2&&reg_size2<numel(I))
% Add new neighbors pixels
for j=1:4,
% Calculate the neighbour coordinate
xn = x2 +neigb(j,1); yn = y2 +neigb(j,2);
% Check if neighbour is inside or outside the image
ins=(xn>=1)&&(yn>=1)&&(xn<=Isizes(1))&&(yn<=Isizes(2));
% Add neighbor if inside and not already part of the segmented area
if(ins&&(J(xn,yn)==0))
neg_pos2 = neg_pos2+1;
neg_list2(neg_pos2,:) = [xn yn I(xn,yn)]; J2(xn,yn)=1;
end
end
% Add a new block of free memory
if(neg_pos2+10>neg_free2), neg_free2=neg_free2+10000; neg_list2((neg_pos2+1):neg_free2,:)=0; end
dist2 = abs(neg_list2(1:neg_pos2,3)-reg_mean2);
[pixdist2, index] = min(dist2);
J2(x,y)=2; reg_size2=reg_size+1;
% Calculate the new mean of the region
reg_mean2= (reg_mean2*reg_size2 + neg_list2(index,3))/(reg_size2+1);
x2 = neg_list2(index,1); y2 = neg_list2(index,2);
% Remove the pixel from the neighbour (check) list
neg_list2(index,:)=neg_list2(neg_pos2,:); neg_pos2=neg_pos2-1;
end
J2=J2>1;

サインインしてコメントする。

### 採用された回答

Stijn Haenen 2020 年 3 月 15 日
Can you upload an image, and give examples of the values: I,x,y,x2,y2,reg_maxdist1,reg_maxdist2, then we can run the code and check whats wrong.
##### 1 件のコメント表示非表示 なし
Cretu Ioana 2020 年 3 月 15 日
Hi Stijn,
I uploaded the image. [x,y]=first seed point, I choosed it [76,76] to obtain to obtain the luminal zone, with reg_maxdist1=0.08 and [68,63] for the second seed point with reg_maxdist1=0.04.
Thank you for your response!

サインインしてコメントする。

### その他の回答 (1 件)

Image Analyst 2020 年 3 月 15 日
I see you've accepted Stijn's answer so your problem is already solved now,
but for what it's worth, I'm attaching my magic wand program. It's similar to the magic wand region growing tool in Photoshop. Maybe it will help other people.

サインインしてコメントする。

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!