How can I find the extension of the common boundary between i and j patches in matlab???

i and j are the two connected regions , In which I want to find the extension of the common boundary between them.....

2 Comments

extension.. do you mean "length"? Or do you mean that you want to project the boundary further?

Sign in to comment.

 Accepted Answer

Where did you upload your image that illustrates this problem? You forgot to tell us the URL so we can see it. So, lacking that the only thing I might suggest is either the convhull() function or the watershed() function http://blogs.mathworks.com/steve/2006/06/02/cell-segmentation/.

7 Comments

http://www.tinyuploads.com/share/files/tyvg8a for this type of image but it must not depend on geometry and independent of the shapes.
Here are the steps. You're going to try to implement these on your own first:
  1. threshold the image at 255 to get a binary image of the white.
  2. call imclearborder() to get rid of the background.
  3. call bwlabel() to label each of the two regions.
  4. for each of the two regions, call imdilate() on the binary image to expand it by one layer of pixels.
  5. Then, AND each pair of dilated regions to find out where they are both true (white).
If you get stuck, let's see your code.
so sorry for late reply and I am grateful to u.I will go through this steps and if stuck then will ask
You may also want to look at my image processing tutorial. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 It's just a short script that illustrates the basic steps in thresholding and measuring objects.
Sir, can you please help me to implement this code as i am new to Matlab and also cant understand the above method which you have described above.Thank you in advance.
Not even any code at all? Here then, try this:
% Demo to find the two blobs and AND them
% together to find the common boundary..
clc; % Clear the command window.
clearvars;
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Mona\Documents\Temporary';
baseFileName = 'Ko0PgU.bmp';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- 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 in the search path folders.', 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);
if numberOfColorBands > 1
grayImage = rgb2gray(grayImage);
end
% 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]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Threshold
binaryImage = grayImage == 255;
% Thicken black lines to close it up
binaryImage = imerode(binaryImage, true(5));
% Get rid of border
binaryImage = imclearborder(binaryImage);
subplot(2, 3, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
% Label the image so we can extract each blob.
[labeledImage numberOfBlobs] = bwlabel(binaryImage);
blob1 = labeledImage == 1;
blob2 = labeledImage == 2;
subplot(2, 3, 3);
imshow(blob1, []);
title('Blob 1', 'FontSize', fontSize);
subplot(2, 3, 4);
imshow(blob2, []);
title('Blob 2', 'FontSize', fontSize);
blob1Dilated = imdilate(blob1, true(7));
blob2Dilated = imdilate(blob2, true(7));
% And these two together to find overlap region
overlap = blob1Dilated & blob2Dilated;
subplot(2, 3, 5);
imshow(overlap, []);
title('Blob 1 & Blob 2', 'FontSize', fontSize);

Sign in to comment.

More Answers (1)

I have referred above code but in that when we apply thresholding on any image and then imerode and imclearborder then it gives the whole black image i mean all pixel values have value '1' , so how to get the number of objects from that image??????

4 Comments

This should have been a comment.
Perhaps when you uploaded it, the web site changed it, like it jpegged it or something. Can you try downloading the image from the web site and trying that one? It will work. Then try to figure out what is different between the web site image and your original image.
It gives the same result .The whole Image contains '1' value.The result is shown in above link...so how to get the two different region here blob1 and blob2?????
I can't help you debug it unless I have the exact image you have, because it worked fine for the image you uploaded.
Yes sir I have downloaded image and then applied the above code it works well but in final section I want to find the extended length of the common boundary. means red line in the image .So can You help me to find out that ?????? I will grateful to you in advance and thanks for help and support.

Sign in to comment.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!