How to create lines and calculate their lenghts
2 次查看(过去 30 天)
显示 更早的评论
I need to create lines in the filtered image bellow (already filtered image of a bubble seeping into a tube (cropped image)) in a similar way to the orange lines (drawn randomly as an example using the software paint) already in the example figure (10 lines is fine) so that I can calculate the lengths of these lines and then make an average. Any idea how i could do this?
Thanks in advance!
cropped
filtered
example
clc;
clear
close all;
load('cropped.mat');
cropped = cortada;
figure, imshow(cropped);
gray = rgb2gray(cropped);
figure, imshow(gray);
thresh = im2bw(gray, 0.7);
figure, imshow(thresh);
remove = bwareaopen(thresh,13200);
figure, imshow(remove);
se = strel('line',400,0);
closingOperation = imclose(remove,se);
figure, imshow(closingOperation);
OriginalLine = closingOperation(1 , :);
OriginalLine2 = closingOperation(end , :);
closingOperation(1, :) = true;
closingOperation(end, :) = true;
filtered = imfill(closingOperation, 'holes');
closingOperation(end,:) = false;
closingOperation(1,:) = false;
filtered(1, :) = OriginalLine;
filtered(end, :) = OriginalLine2;
figure, imshow(filtered);
4 个评论
回答(1 个)
Image Analyst
2020-11-28
Jordan:
Why not do it for ALL widths (every single line of the blob), rather than just 10? Just simply do
verticalProfile = sum(binaryImage, 2); % A list of all possible widths - hundreds of them.
meanWidth = mean(verticalProfile);
If you really want exactly 10 lines dividing the blob into 11 sections, do this (untested):
[r, c] = find(binaryImage);
topRow = min(r)
bottomRow = max(r)
rows = linspace(bottomRow, topRow, 12); % 12 if you include the top row and bottom row.
% Don't include very top or very bottom
rows = rows(2:end-1) % Only 10 now.
for k = 1 : length(rows)
row = rows(k);
col1 = find(binaryImage(row, :), 1, 'first');
col2 = find(binaryImage(row, :), 1, 'last');
width(k) = col2 - col1; % Add 1 if you want, depends on your definition of width.
end
6 个评论
Image Analyst
2020-11-30
But you actually did because Rik said to use sum() and find() but didn't give any code, and you said it worked. I also said that and additionally gave code for how to find the location of the "orange lines". So if you coded up Rik's suggestion, you actually did something like what I gave above.
Rik
2020-11-30
And that is the reason why I didn't post my suggestion as an answer, as this answer gives a specific example of how to implement my suggestion.
另请参阅
类别
在 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!