How to create lines and calculate their lenghts
조회 수: 1 (최근 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!