How to create lines and calculate their lenghts

2 vues (au cours des 30 derniers jours)
Jórdan Venâncio Leite
Jórdan Venâncio Leite le 17 Oct 2020
Commenté : Rik le 30 Nov 2020
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 commentaires
Jórdan Venâncio Leite
Jórdan Venâncio Leite le 28 Nov 2020
Hi Rik! Put your answer bellow so i can choose as the best answer!!
Jórdan Venâncio Leite
Jórdan Venâncio Leite le 30 Nov 2020
It worked!!

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 28 Nov 2020
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 commentaires
Image Analyst
Image Analyst le 30 Nov 2020
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 le 30 Nov 2020
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by