Extract position data of bubble from an image
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nhat Nguyen
am 8 Nov. 2022
Beantwortet: Image Analyst
am 8 Nov. 2022
Hi expert,
How can I tracing my object's boundaries without the frame?
I = imread('image.bmp');
threshold = graythresh(I);
BW=im2bw(I,0.9);
dim = size(BW);
col = round(dim(2)/2)-90;
row = min(find(BW(:,col)));
boundary = bwtraceboundary(BW,[row, col],'S');
imshow(I)
hold on;
plot(boundary(:,2),boundary(:,1),'g','LineWidth',3);
Thank you!

2 Kommentare
Akzeptierte Antwort
Image Analyst
am 8 Nov. 2022
Try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
markerSize = 40;
rgbImage = imread('image2.bmp');
subplot(2, 1, 1);
imshow(rgbImage);
impixelinfo
mask = rgbImage(:, :, 1) > 240;
% Take largest blob and invert it.
mask = ~bwareafilt(mask, 1);
% Get rid of small specks.
mask = bwareafilt(mask, 1);
subplot(2, 1, 2);
imshow(mask)
title('Mask Image')
% Plot the borders of all the blobs in the overlay above the original image
% using the coordinates returned by bwboundaries().
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
subplot(2, 1, 1);
% Here is where we actually get the boundaries for each blob.
boundaries = bwboundaries(mask);
% boundaries is a cell array - one cell for each blob.
% In each cell is an N-by-2 list of coordinates in a (row, column) format. Note: NOT (x,y).
% Column 1 is rows, or y. Column 2 is columns, or x.
numberOfBoundaries = size(boundaries, 1); % Count the boundaries so we can use it in our for loop
% Here is where we actually plot the boundaries of each blob in the overlay.
hold on; % Don't let boundaries blow away the displayed image.
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k}; % Get boundary for this specific blob.
x = thisBoundary(:,2); % Column 2 is the columns, which is x.
y = thisBoundary(:,1); % Column 1 is the rows, which is y.
plot(x, y, 'r-', 'LineWidth', 2); % Plot boundary in red.
end
hold off;
caption = sprintf('%d Outlines, from bwboundaries()', numberOfBoundaries);
fontSize = 15;
title(caption, 'FontSize', fontSize);
axis('on', 'image'); % Make sure image is not artificially stretched because of screen's aspect ratio.

0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
