Extract position data of bubble from an image

조회 수: 2 (최근 30일)
Nhat Nguyen
Nhat Nguyen 2022년 11월 8일
답변: Image Analyst 2022년 11월 8일
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
KSSV
KSSV 2022년 11월 8일
Attach your original image.
Nhat Nguyen
Nhat Nguyen 2022년 11월 8일
here you go, I want extract to boundary data of this object

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2022년 11월 8일
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개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by