by Nevine Jac » Sat, 21 Jan 2006 01:24:37
i All,
I had forsaken this part of the code for some time now and I have
been in the process of resurrecting it for the last two days. With
great help from Jerome and significant others, I have advanced well
but I am now stuck at a certain point and would appreciate your help.
(The details below are fairly long but they should be simple to
comprehend. So don't get vexed by looking at the long message)
Here's what I require the code to do:
1) Draw rectangles (yellow colored) around the objects of the binary
image
2) Once a rectangle is selected by mouse clicking, the rectangle
should be of different color (green) and the object below it should
be deleted (need not be displayed though).
3) Once I am done selecting the rectangles (that is, objects) to be
deleted, there must be a way by which no more rectangles can be
selected and the new image with objects removed is displayed
(probably by clicking a "Done with Selection" button on the Figure
Window).
Here's what the code does:
1) Draws rectangles (yellow colored) around the objects of the binary
image
2) Once a rectangle is selected by mouse clicking, the rectangle is
of green color BUT the object below it is not deleted.
3) There is NO "Done with Selection" button.
Here's my code (I've modified it a bit to keep it simple):
******************************
% Declaring these variables as Global
global Ltemp stats
% img is a binary image with objects in them
[L,maxi] = bwlabel(img);
stats = regionprops(L,'BoundingBox');
colormap(gray)
im=image(L);
set(im,'hittest','off');
% Plots yellow rectangles around each object
for i = 1:maxi
rectangle('Position',stats(i).BoundingBox,
'EdgeColor','y','linewidth',2,'hittest','off');
end
set(gca,'buttondownfcn','bdf');
************************************
function bdf
% Declares the variables to be global (again)
global Ltemp stats
h=flipud(findobj('type','rectangle'));
% Gets position of mouse click
cp=get(gca,'currentpoint');
flag=zeros(length(h),1);
% Checks which rectangle the mouse click corresponds to
for n=1:length(h)
pos=get(h(n),'position');
flag(n)=inpolygon(cp(1,1),cp(1,2),...
[pos(1) pos(1)+pos(3) pos(1)+pos(3) pos(1)],...
[pos(2) pos(2) pos(2)+pos(4) pos(2)+pos(4)]);
end
idx=find(flag);
% Displays the rectangle number (object number) as the title
title(num2str(idx))
% Get handle of the original image
h1 = get(gca);
% Store value of original image in Ltemp
% Ltemp is equal to original value of L, for the first time
Ltemp = get(h1.Children(end),'CData');
% Delete object clicked by mouse
Ltemp(Ltemp==idx) = 0;
% Set Original Value of Image to Ltemp
set(h1.Children(end),'CData',Ltemp);
% Set color of selected rectangle to green
rectangle('Position',stats(idx).BoundingBox, 'EdgeColor','g');
*****************************************
From the above codes, I see that each time I click on a rectangle,
the object below is deleted and the new image stored in Ltemp. So
after selecting several rectangles, I finally see that the final
value of Ltemp has all those selected objects deleted. This is
ofcourse what I want, but, how do I stop selecting the rectangles and
finally display a new image with all objects deleted?
Also, this works only when I use the "image" function. It does not
work for imshow. That is, when I replace the line "im = image(L)" by
"im = imshow(L)", I get an error.
I would