How to select an object if you click it?

조회 수: 5 (최근 30일)
Meshooo
Meshooo 2014년 1월 15일
댓글: SC P 2018년 11월 26일
Dear all,
I have an image the contains few objects as I show here. I want that if the user click inside an object using the mouse then this clicked object will remain and all other objects will be removed from the image.
Is there someway to do that?
Any help will be appreciated.
Meshoo

채택된 답변

Image Analyst
Image Analyst 2014년 1월 15일
Yes. Follow these steps
  1. label the binary image with bwlabel
  2. call [column, row] = int32(ginput(1)) to let the user click somewhere
  3. get the label with labelNumber = labeledImage(row, column)
  4. extract the object with extractedObject = ismember(labeledImage, labelNumber)
  5. Make it binary again binaryImage = extractedObject > 0;
  6. display it with imshow(binaryImage, []);
  댓글 수: 2
Meshooo
Meshooo 2014년 1월 15일
clear all
clc
%
I = imread('regular_shapes.tif');
%
BW = im2bw(I);
%
figure, imshow(BW);
hold on
[yCenter, xCenter] = ginput(1)
hold off
%
b = bwboundaries(BW);
%
[L, num_Obj] = bwlabel(BW, 4);
%
for k = 1:num_Obj;
Obj = L ==k;
bb = b{k};
X_obj = bb(:, 1);
Y_obj = bb(:, 2);
Selec{k} = inpolygon(xCenter,yCenter,X_obj,Y_obj);
end
Selec;
%
Selec = [Selec{:}];
[value,index] = max(Selec);
%
Obj = L ==index;
%
figure, imshow(Obj);
SC P
SC P 2018년 11월 26일
Error came while running script"
Brace indexing is not supported for
variables of this type.
Error in boundin_box_26_11 (line 75)
Selec = [Selec{:}];

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by