Problem in using bwlabel() for labeling individual fiber segments in a skeleton (with branchpoints removed) ?
2 次查看(过去 30 天)
显示 更早的评论
I am facing a problem while applying the bwlabel() for labeling the different fiber segments. I want to label the different fiber segments in a network.
To separate out the different fiber segments I found out the branchpoints and subtracted that along with its 3x3 neighborhood from the original image. Then I applied the bwlabel to the image with connectivity of 8. This should have labeled all the fiber segments. Right?
But surprisingly it is including the neighboring fiber segments. Using a connectivity of 4 shows a labeling of upto 4849 segments. Using connectivity of 8 shows just 24 segments. Even bwconncomp() returns the same result as 24. How is this possible since clearly the number of fiber segments is more than 24? Am I doing it wrong or something?
I have attached the image of the skeleton with its branchpoints and 3x3 neighborhood removed. I want to label the individual fiber segments i.e. the different branches in the network to determine their characteristics length, spatial orientation preference and other characteristics?
0 个评论
采纳的回答
Image Analyst
2013-12-16
You do realize that a 4-connected labeling will have a lot more blobs than a 8-connected labeling, right? I did an 8-connected with your image where I did
binaryImage = grayImage > 200;
and I got 444 blobs . You posted a jpg rather than a PNG so we don't have your exact image, just one with horrible jpeg artifacts . You need to post the exact image with no lossy compression if you want us to use the same image. That means PNG (or BMP or TIFF). So basically I can't replicate your results.
2 个评论
Image Analyst
2013-12-16
I still get 444 blobs. Here is my code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
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
baseFileName = 'skeleton with branchpoint removed.png'; % Default
% Read in gray scale demo image.
folder = 'C:\Users\Rajesh\Documents';
% 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
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 1, 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')
% Label each blob with 8-connectivity, so we can make measurements of it
binaryImage = grayImage > 200;
% Get rid of white border.
binaryImage = imclearborder(binaryImage);
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
subplot(2, 1, 2);
imshow(coloredLabelsImage);
title('Labeled Image', 'FontSize', fontSize);
fprintf('The number of blobs is %d.\n', numberOfBlobs);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!