- Obtain the PixelList property of each line using regionprops
- Compute the difference in location between pixels (gives you an idea of how much the line wiggles)
- Maybe take the mean of this difference
- And weight it with the number of pixels in this segment
Image Edges: Calculate complexity of a line segment?
조회 수: 5 (최근 30일)
이전 댓글 표시
Can anyone suggest a good way to calculate the 'complexity' of a line segment (obtained from 'bwlabel' after 'canny' edge detection).
I want to define 'complexity' in 2 parts:
- How straight the line is
- How long the line is
and would like to weight each line segment such that a long and straight line is more favourable than a short and wavy line.
It is ok for the line to change direction so long as they do not change direction regularly (for example, a large square is fine because it is made up of 4 'simple' straight lines). However, edges corresponding to leaves on a tree for example are not good because they change direction too much.
As mentioned, I have used 'bwlabel' after 'canny' edge detection. I then want to iterate through each bwlabel number independently and rank them in order of how (predominately) straight and long they are.
Many thanks for your help!
댓글 수: 0
답변 (3개)
Ashish Uthama
2012년 4월 6일
(I'll try to flesh this soon) How about:
댓글 수: 1
Walter Roberson
2012년 4월 6일
In a line that curves, you can get pixel lists where the list does not follow the "outside" (or "inside") of the curve. For example,
.x..
xxx.
x..x
then the ordering of the pixels in the section that touches itself is not necessarily going to "thread" the line.
It might make more sense to use http://www.mathworks.com/help/toolbox/images/ref/bwtraceboundary.html as at least then you know the order of the tracing.
Image Analyst
2012년 4월 6일
Usually the tortuosity ( http://en.wikipedia.org/wiki/Tortuosity) is what is used. I think it's sometimes called "curl" when dealing with fibers. It is the ratio of the length to the distance between the endpoints. A number of alternative definitions are also discussed on that web page.
댓글 수: 3
Image Analyst
2012년 4월 10일
Not how I'd do it. How did you get x1 and x2? I'd call bwmorph to get the endpoints, then calculate the distance for each labeled object. Then get the histogram - use as many bins as there are objects. This will get you the sum of all the lengths of all the lines in just one line of code: perimeters = hist(LS, qty). Then divide them. Sort them if desired.
Image Analyst
2012년 4월 11일
Philip: Alright, try this code:
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;
% 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
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Users\Philip\Documents\Temporary';
baseFileName = 'edgese.png';
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 Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
binaryImage = grayImage > 0;
[labeledImage numberOfLines] = bwlabel(binaryImage);
fprintf('numberOfLines = %d\n', numberOfLines);
endpoints = bwmorph(binaryImage, 'endpoints');
subplot(2, 2, 2);
imshow(endpoints, []);
title('Endpoints Image', 'FontSize', fontSize);
% Number of Endpoints should = 2 * numberOfLines because each line will have two endpoints.
numberOfEndpoints = sum(endpoints(:));
fprintf('numberOfEndpoints = %d\n', numberOfEndpoints);
% Find the length of each line
lineLengths = histc(labeledImage(:), 1:numberOfLines)
% Find the endpoints for each
% Then find the distance and the tortuosity.
for lineNumber = 1 : numberOfLines
theseEndpoints = (labeledImage .* endpoints) == lineNumber;
subplot(2, 2, 3);
imshow(theseEndpoints, []);
caption = sprintf('Endpoints for line #%d', lineNumber);
title(caption, 'FontSize', fontSize);
drawnow;
[rows columns] = find(theseEndpoints);
distanceBetweenEndpoints = sqrt((rows(1)-rows(2))^2 + (columns(1)-columns(2))^2);
tortuosity(lineNumber) = lineLengths(lineNumber) / distanceBetweenEndpoints;
fprintf('For line #%d, curve length = %.2f, distance = %.2f,tortuosity = %.3f\n',...
lineNumber, lineLengths(lineNumber), distanceBetweenEndpoints, tortuosity(lineNumber));
end
댓글 수: 9
Image Analyst
2012년 4월 12일
By the way, make sure your blobs have been skeletonized first (use bwmorph) so that they are only a single pixel wide.
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!