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.....
2 个评论
Walter Roberson
2013-2-10
extension.. do you mean "length"? Or do you mean that you want to project the boundary further?
采纳的回答
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 个评论
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
2013-4-7
4 个评论
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!