How to create lines and calculate their lenghts

1 回表示 (過去 30 日間)
Jórdan Venâncio Leite
Jórdan Venâncio Leite 2020 年 10 月 17 日
コメント済み: Rik 2020 年 11 月 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 件のコメント
Jórdan Venâncio Leite
Jórdan Venâncio Leite 2020 年 11 月 28 日
Hi Rik! Put your answer bellow so i can choose as the best answer!!
Jórdan Venâncio Leite
Jórdan Venâncio Leite 2020 年 11 月 30 日
It worked!!

サインインしてコメントする。

回答 (1 件)

Image Analyst
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
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
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 ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by