Home > Software engineering >  Help you a great god ~ about the region growing image segmentation algorithm
Help you a great god ~ about the region growing image segmentation algorithm

Time:10-19

To briefly describe the problem: matlab mark the following two parts (as shown in figure 1)
I am using region growing algorithm, when I selected the left any point of the area of the program run successfully (figure 2)
But when I selected the right area of the point, the program is run error, tip:????? Attempted to access neg_list (0, :); The index must be a positive integer or logical.

The Error in==& gt; Untitled1 at 92
Neg_list (index, :)=neg_list (neg_pos, :);
Then I choose the other one point, the result is figure 3
Surprised,,, why didn't part of the image on the right side of the treated?
The enclosed code:
% Segment -based on area, Region Growing;
clear all; close all; CLC
[fileName, the pathName]=uigetfile (' *. * ', 'both Please select an image "); % basket, select the file
If (fileName)
FileName=strcat (pathName, fileName);
FileName=lower (fileName); % consistent lowercase letters form
The else
J=0; % to record what region growing segmentation of area
Msgbox (' both Please select an image ");
return; Exit %
End

I=imread (fileName);
If (~ (size (I, 3) - 3))
I=rgb2gray(I); % into single channel grayscale
End
I=im2double (I);

Interactive selection based on seeds point %
If (exist (' x ', 'var')==0 & amp; & Exist (' y ', 'var')==0)
Figure, imshow (I, []);
hold on;
[y, x]=getpts; % the mouse point enter
X=round (x (1)); % selecting seeds
Y=round (y (1));
End

If (nargin==0)
Reg_maxdist=0.1;
% nargin is a skill, is commonly used in matlab code is mainly used for calculating the input parameters of the current main function a
% number, generally can be according to the return value to determine the main function of nargin, the default value of the input parameters in implementation, if
% user input parameter number is zero, then the default is 0.2
End
J=zeros (size (I)); % the main function of the return value, record the regional growth of
Isizes=size (I);
Reg_mean=I (x, y); % said good segmentation area average, initialized to the seed point grey value of the
Reg_size=1; % split into regional, initialize only seed points in a
Neg_free=100000; % dynamically allocated memory for each application of continuous space size
Neg_list=zeros (neg_free, 3);
% defined list of neighborhood, and pre-allocated used for storage to analysis the pixel coordinates and the space of grey value, speed up
% if the image is larger, it is necessary to combine neg_free to achieve the dynamic allocation of memory matlab
Neg_pos=0; % to record to be analysed by the number of pixels in the neg_list
Pixdist=0;
% record pixels to increase the distance to the segmented regions after the latest measure
% the next to be analysed four neighborhood pixels and the seed point distance
% if the current coordinates (x, y) by neigb we can get the position of the four neighborhood pixels
Neigb=[1 0;
1 0;
0 and 1;
0, 1];
% to regional growth, when what is to be analyzed, neighborhood pixels and has good segmentation region gray levels of pixels from the
% than reg_maxdis, region growing end
Counter=0;
While (pixdist & lt; 0.06 & amp; & Reg_size & lt; 569491)
% increase new neighborhood pixels in neg_list

For j=1:4
Xn=x + neigb (j, 1);
Yn=y + neigb (j, 2);
% check over the boundary of the image neighborhood pixels
Ins=(xn>=1) & amp; & (yn>=1) & amp; & (xn<=Isizes (1)) & amp; & (yn<=Isizes (1));
% if neighborhood pixels within the image, and has not been good segmentation; Then add it to the list of neighborhood
If (ins & amp; & J (xn, yn)==0)
Neg_pos=neg_pos + 1;
Neg_list (neg_pos, :)=[xn, yn, I (xn, yn)]; % storage corresponding points of grey value
J (xn, yn)=1; % with the neighborhood pixels has been visited doesn't mean that he
in the area of the segmentationCounter=counter + 1;
End
End
% if the allocated memory empty asked enough, apply for a new memory space
If (neg_pos + 10 & gt; Neg_free)
Neg_free=neg_free + 100000;
(neg_pos neg_list (+ 1) : neg_free, :)=0.
End
% from to be analyzed by the pixel points to select a pixel, the point at which a grey value and has good segmentation region grayscale average
% of the absolute value of the pixel to be analysed in the smallest
Dist=abs (neg_list (1: neg_pos, 3) - reg_mean);
[pixdist, index]=min (dist);
The mean new % calculation domain
Reg_mean=(reg_mean * reg_size + neg_list (index, 3))/(reg_size + 1);
Reg_size=reg_size + 1;
% of the old seed points marked as has good segmentation region pixels
J (x, y)=2; % sign the pixel is already a good segmentation pixels
X=neg_list (index, 1);
Y=neg_list (index, 2);
% pause (0.0005); % dynamic map
% the if (J (x, y)==2)
% plot (x, y, "r.");
% end
% the new seed points removed from the list of neighborhood pixels to be analysed

Neg_list (index, :)=neg_list (neg_pos, :);
Neg_pos=neg_pos - 1;
End
J=(J==2); % before we will be good segmentation pixel labeled 2
Hold off.
Counter;
Figure, imshow (I + J);

CodePudding user response:

Matlab can single step or set breakpoint debugging,
  • Related