"Region grow"

조회 수: 16 (최근 30일)
Marlene
Marlene 2011년 12월 22일
Hi, anyone know how do I analyze a pixel and its four neighbors? and if any of these neighbors have a similar intensity to the pixel how do I put it in a new image with the value 1?
  댓글 수: 3
Marlene
Marlene 2011년 12월 23일
is similar to the difference between the pixel and the neighboring pixel is less than T. the image has 256 gray levels. I'm not able to write the code to add similar pixels into a new image (which is binary).
Image Analyst
Image Analyst 2011년 12월 23일
See my demo below which does this.

댓글을 달려면 로그인하십시오.

답변 (4개)

Sean de Wolski
Sean de Wolski 2011년 12월 22일
doc blockproc;
doc colfilt
  댓글 수: 2
Marlene
Marlene 2011년 12월 22일
but I do not understand how the function blocksproc works. What is the fun parameter?
Walter Roberson
Walter Roberson 2011년 12월 23일
fun is a function handle of a routine that will analyze the individual block and return the new value.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 12월 23일
What do you want to do on the image boundaries?
Is this a truecolor (RGB) image, a grayscale image, a pseudocolor image?
What is to be put in to the new image if the pixel is determined not to be similar?
Think about what you could do with diff(IMG,1)
You may not need blockproc() for this task, if the definition of "similar to" is sufficiently regular.
  댓글 수: 2
Marlene
Marlene 2011년 12월 23일
Hi Walter,
My image is the gray levels. If the neighboring pixels are not similar were to zero in the new image. If they are similar to the value 1. My problem is I do not know how to write code to put the pixel(i, j)being analyzed in new image with value 1 and a pixel, for example, (i, j +1) is added to the new image with the value 1 if this is similar to pixel (i, j) of the gray image.
Marlene
Marlene 2011년 12월 23일
I wrote this code
A=zeros(size(imgm));
S=bwareaopen(B1,5); %seeds
% figure,imshow(S,[])
T=0.02; %threshold
J = find(S); %position of seeds
S1 = img2(J); %array of seeds
A=S;
for i=2:u-1
for j=2:t-1
for k = 1:length(S1)
seed(k) = S1(k);
if abs(seed(k)-img2(i-1,j))<=T
A(i-1,j)=1;
else if abs(seed(k)-img2(i,j-1))<=T
A(i,j-1)=1;
else if abs(seed(k)-img2(i+1,j))<=T
A(i+1,j)=1;
else if abs(seed(k)-img2(i,j+1))<=T
A(i,j+1)=1;
else A(i,j)=0;
end
end
end
end
end
end
end
but there are seeds that are not growing and points that are not seeds to grow ... And I just want to grow the seeds of neighboring pixels. Anyone know where I'm wrong?

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2011년 12월 23일
Marlene, just compute the morphological erosion and subtract it from your original, then threshold. It's like 4 lines. You'll need imerode from the Image Processing Toolbox. Do you have that toolbox?

Image Analyst
Image Analyst 2011년 12월 23일
Marlene: I sense you might need more "help" than my last answer so here is a full blown demo. It does what you said in your first comment. Essentially it's still 4 lines:
  1. Construct a structuring element for the 4 neighbors
  2. Do a morphological erosion
  3. Subtract from the original image
  4. Threshold the absolute value of the difference.
It just has some extra stuff in there to make it a fancy demo with displays, etc.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Rename figure title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Get the minimum in a cross shaped kernel
% This is the min value in the four 4-connected neighbors.
se = [0 1 0; 1 0 1; 0 1 0];
localMinImage = imerode(grayImage, se);
% Display the local min image.
subplot(2, 3, 2);
imshow(localMinImage, []);
title('Local Min Image (Erosion)', 'FontSize', fontSize);
% Subtract it from the original
diffImage = grayImage - localMinImage;
% Display the difference image.
subplot(2, 3, 3);
imshow(diffImage, []);
title('Difference Image', 'FontSize', fontSize);
% Compute and display the histogram of the difference image.
[pixelCount grayLevels] = imhist(abs(diffImage));
subplot(2, 3, 4);
bar(grayLevels, pixelCount);
grid on;
xlim([0 255]);
caption = sprintf('Histogram of the Absolute Value of\nDifference Image');
title(caption, 'FontSize', fontSize);
% Threshold the difference image
% Ask user for a threshold.
defaultThresholdValue = 45;
userPrompt = 'Enter the threshold value';
caUserInput = inputdlg(userPrompt, 'Enter the threshold value',1,{num2str(defaultThresholdValue)});
thresholdValue = round(str2num(cell2mat(caUserInput)));
% Check for a valid integer.
if isempty(thresholdValue)
% They didn't enter a number.
% They entered a character, symbols, or something else not allowed.
thresholdValue = defaultThresholdValue;
message = sprintf('I said it had to be an integer.\nI will use %d and continue.', thresholdValue);
uiwait(warndlg(message));
end
% Threshold the imnage with the user supplied threshold.
binaryImage = abs(diffImage) > thresholdValue;
% Display the binary image.
subplot(2, 3, 5);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
  댓글 수: 6
Marlene
Marlene 2011년 12월 26일
These are my pictures,
http://s1178.photobucket.com/albums/x378/msmaxado/
The first is that the image of birth for the seeds - the second image.
I want to grow the white dots of second image(seeds) to something that looks like the white regions and separated from the third image.
Marlene
Marlene 2011년 12월 27일
Image Analiyst you have news for me?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by