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

5 次查看(过去 30 天)
i and j are the two connected regions , In which I want to find the extension of the common boundary between them.....

采纳的回答

Image Analyst
Image Analyst 2013-2-10
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 个评论
Mona
Mona 2013-4-6
编辑:Mona 2013-4-6
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.
Image Analyst
Image Analyst 2013-4-7
编辑:Image Analyst 2013-4-7
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);

请先登录,再进行评论。

更多回答(1 个)

Mona
Mona 2013-4-7
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 个评论
Image Analyst
Image Analyst 2013-4-8
I can't help you debug it unless I have the exact image you have, because it worked fine for the image you uploaded.
Mona
Mona 2013-4-8
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.

请先登录,再进行评论。

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by