Info

此问题已关闭。 请重新打开它进行编辑或回答。

Find degree of branching using circular neighbourhood method matlab

1 次查看(过去 30 天)
I have a skeleton image. as shown on following link.
I have detected branchpoints and endpoints and labelled the image. Now I am drawing circle on each branch and I am using following code to draw a circle on each branch.
mn=bwmorph(y,'branchpoints');
[row column] = find(mn);
branchPts = [row column];
endImg = bwmorph(y, 'endpoints');
[row column] = find(endImg);
endPts = [row column];
figure;imshow(y);
hold on ;
plot(branchPts(:,2),branchPts(:,1),'rx');
hold on; plot(endPts(:,2),endPts(:,1),'*');
% Labeling the Branches
branches = (y & ~mn); % set branch points to zero
figure; imshow(branches);
branchesLabeled = bwlabel( branches); % label connected components
vislabels(branchesLabeled)
% Calculation of Length of Branches and Circular Neighbourhood Method for
% for detection of normal and abnormal branches.
sts = regionprops( branchesLabeled,'Area', 'Perimeter','MajorAxisLength','Centroid' );
figure
imshow(branchesLabeled)
hold on
% extract properties
% Loop for circles
for i=1:size(sts)
r= sts(i).MajorAxisLength/2 ; %desired radius
centerx = sts(i).Centroid(1);
centery = sts(i).Centroid(2);
th = 0:pi/50:2*pi;
xunit = r * cos(th) + centerx;
yunit = r * sin(th) + centery;
plot(xunit, yunit);
end
I have couple of problems with this code.
The circles are drawn on center line of skeleton(It is not a branch it is center line of skeleton). I want circles only on branches and not on skeleton center line.
How to detect only branches in skeleton? I am storing branchpoints in mn variable in above code and to label it i am inverting those branchpoints with my skeleton image
branches = (y & ~mn);
Because of this my center line is breaking and code is considering non connected center line as branch and drawing circle on it. Is there a way to label the branch points and drawing circle on branches only?
  3 个评论

回答(1 个)

Image Analyst
Image Analyst 2013-1-26
I'm not really sure what you want to do. You have a skeleton and then identify branchpoints and break the skeleton apart into individual brand segments. Then you place a circle at the centroid of each branch which has a diameter that is approximately the length of the branch. It's doing what you told it to do. If you want circles only at the "branchpoints" only, then don't loop over all branches placing circles at the centroid of each branch, loop over branchpoints (not branches) and place circles at the branchpoint locations (not the branch centroids).
  7 个评论
Image Analyst
Image Analyst 2013-1-31
clc;
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
% 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
grayImage = peaks(256);
% Display the original image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Image for deriving a binary image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Get a binary image.
binaryImage = grayImage > 3;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage, []);
title('The Starting Binary Image', 'FontSize', fontSize);
% Erode it to form a marker image.
% Erode it wnough to have only 2 blobs instead of 3
markerImage = imerode(binaryImage, ones(15));
% Display the image.
subplot(2, 2, 3);
imshow(markerImage, []);
title('Marker Image = Eroded Binary Image', 'FontSize', fontSize);
reconst = imreconstruct(markerImage, binaryImage);
% Display the reconstructed image.
subplot(2, 2, 4);
imshow(reconst, []);
title('Final Reconstructed Image', 'FontSize', fontSize);
Image Analyst
Image Analyst 2013-1-31
Second demo:
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 = 20;
% 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 = 'eight.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, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf,'name','Image Analysis Demo','numbertitle','off')
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
maskImage = imfill(grayImage < 220, 'holes');
% Display the image.
subplot(2, 2, 2);
imshow(maskImage, []);
title('Mask Image (Original Image Thresholded)', 'FontSize', fontSize);
markerImage = false(size(maskImage));
markerImage(20:70, 225:230) = true;
% Display the image.
subplot(2, 2, 3);
imshow(markerImage, []);
title('Marker Image', 'FontSize', fontSize);
finalImage = imreconstruct(markerImage, maskImage);
% Display the image.
subplot(2, 2, 4);
imshow(finalImage, []);
title('Final Reconstructed Image', 'FontSize', fontSize);

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by