How can I create draggable lines in a BW-Mask in an image overlay?

3 views (last 30 days)
Hi!
I created a GUI which is able to plot agarose gels (<http://en.wikipedia.org/wiki/Gel_electrophoresis>) and automatically recognize the gel lanes by the intensity profile. The minima get eroded and detected and these positions are used for the creation of a black and white mask for my image. Then I isolate the edges of the regions yielding rectangles which actually surround the individual lanes. The problem is that the lanes in a gel are not always 100% straight or easy to recognize. I need something, where the user can correct the lane mask by manually dragging the edges of the rectangles in horizontal direction.
Is this possible? If not, are there maybe any work-arounds like drawing imrect over the rectangles of the mask?
Any help is much appreciated.
Thanks! Janett

Accepted Answer

ChristianW
ChristianW on 14 Mar 2013
This might be usefull for you:
function test
close all
imagesc(peaks), axis off, axis image, hold on
d = [10 25 20 30]; % rectange distances [x1 x2 y1 y2]
p = plot_rect(d);
set(gcf,'KeyPressFcn',@adapt_rect)
def_str = 'Press keyboard for rectangle adaption';
t = text(1,-2,def_str,'fontsize',10,'color',[1 1 1]);
function adapt_rect(src,event)
set(t,'string','Locate a new rectangle corner.')
[x,y] = ginput(1); % [x, y] = getpts
[~,Ix] = min(abs(d(1:2)-x));
d(Ix) = x;
[~,Iy] = min(abs(d(3:4)-y));
d(Iy+2) = y;
delete(p)
p = plot_rect(d);
set(t,'string',def_str)
end
end
function p = plot_rect(d)
R = [d(1) d(3); d(1) d(4); d(2) d(4); d(2) d(3); d(1) d(3)];
p = plot(R(:,1),R(:,2),'k','LineWidth',2);
end
  2 Comments
ChristianW
ChristianW on 18 Mar 2013
Yes sure, you can. I am sorry, I overread this part. Basically its the WindowButtonMotionFcn doing that job. I've learned alot regarding this from Matt Tearle's doodle.
function test
close all
f = figure;
ax = axes;
imagesc(peaks), axis off, axis image, hold on
d = [10 25 20 30]; % rectange distances [x1 x2 y1 y2]
p = plot_rect(d);
set(f,'WindowButtonDownFcn',@start_drag)
uiwait(f)
function start_drag(src,event)
cp = get(ax,'CurrentPoint');
z = cp(1,[1 1 2 2]);% [x x y y] x and y position to compare with d
[~,I] = min(abs(d-z)); % find the closest
d(I) = z(I); % drag the found one
set(src,'pointer','crosshair')
set(src,'WindowButtonMotionFcn',@drag)
set(src,'WindowButtonUpFcn',@stop_drag)
function drag(~,~)
cp = get(ax,'CurrentPoint');
z = cp(1,[1 1 2 2]);% [x x y y] x and y position to compare with d
d(I) = z(I); % drag the found one
delete(p)
p = plot_rect(d);
drawnow
end
function stop_drag(src,~)
set(src,'Pointer','arrow')
set(src,'WindowButtonMotionFcn',[])
set(src,'WindowButtonUpFcn',[])
uiresume(f)
end
end
end
function p = plot_rect(d)
R = [d(1) d(3); d(1) d(4); d(2) d(4); d(2) d(3); d(1) d(3)];
p = plot(R(:,1),R(:,2),'k','LineWidth',2);
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by