Skip to content

Commit 12071d3

Browse files
committed
add FloodFillTool.m
1 parent a46f681 commit 12071d3

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

ImageM/+imagem/+gui/FrameMenuBuilder.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ function buildImageFrameMenu(obj, hf)
297297
'Set Pixel to White', true);
298298

299299
addMenuItem(obj, toolsMenu, SelectTool(@Brush), 'Brush');
300-
addMenuItem(obj, toolsMenu, PlotLabelMapCurvesFromTable(), 'Plot Curves From Labels...');
300+
addMenuItem(obj, toolsMenu, SelectTool(@FloodFillTool), 'Flood Fill');
301+
addMenuItem(obj, toolsMenu, PlotLabelMapCurvesFromTable(), 'Plot Curves From Labels...');
301302
action = SelectTool(@PlotImage3DZProfile);
302303
addMenuItem(obj, toolsMenu, action, 'Plot Image3D Z-Profile');
303304
action = SelectTool(@PlotVectorImageChannels);

ImageM/+imagem/+tools/Brush.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313
% Author: David Legland
1414
1515
% Created: 2011-11-21, using Matlab 7.9.0.529 (R2009b)
16-
% Copyright 2011 INRA - Cepia Software Platform.
16+
% Copyright 2011 INRAE - Cepia Software Platform.
1717

1818
%% Properties
1919
properties
2020
ButtonPressed = false;
21-
22-
% % The current drawing 'value', initialized to white
23-
% Value = 255;
24-
21+
2522
PreviousPoint;
2623
end
2724

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
classdef FloodFillTool < imagem.gui.Tool
2+
% Set pixel color to white
3+
%
4+
% output = FloodFillToolTool(input)
5+
%
6+
% Example
7+
% FloodFillToolTool
8+
%
9+
% See also
10+
%
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2011-11-21, using Matlab 7.9.0.529 (R2009b)
16+
% Copyright 2011 INRA - Cepia Software Platform.
17+
18+
%% Properties
19+
properties
20+
ButtonPressed = false;
21+
end
22+
23+
%% Constructor
24+
methods
25+
function obj = FloodFillTool(viewer, varargin)
26+
% Creates a new tool using parent gui and a name
27+
obj = [email protected](viewer, 'floofill');
28+
end % constructor
29+
30+
end % construction function
31+
32+
%% General methods
33+
methods
34+
function onMouseButtonPressed(obj, hObject, eventdata) %#ok<INUSD>
35+
processCurrentPosition(obj);
36+
obj.ButtonPressed = true;
37+
end
38+
39+
function onMouseButtonReleased(obj, hObject, eventdata) %#ok<INUSD>
40+
obj.ButtonPressed = false;
41+
end
42+
43+
function onMouseMoved(obj, hObject, eventdata) %#ok<INUSD>
44+
if ~obj.ButtonPressed
45+
return;
46+
end
47+
processCurrentPosition(obj);
48+
end
49+
50+
function processCurrentPosition(obj)
51+
doc = currentDoc(obj);
52+
img = doc.Image;
53+
54+
if ~isScalarImage(img)
55+
return;
56+
end
57+
58+
point = get(obj.Viewer.Handles.ImageAxis, 'CurrentPoint');
59+
coord = round(pointToIndex(obj, point(1, 1:2)));
60+
61+
% control on bounds of image
62+
if any(coord < 1) || any(coord > size(img, [1 2]))
63+
return;
64+
end
65+
66+
% apply floodfill and update current image
67+
res = floodFill(img, coord, obj.Viewer.Gui.App.BrushValue);
68+
img.Data = res.Data;
69+
70+
updateDisplay(obj.Viewer);
71+
end
72+
73+
function index = pointToIndex(obj, point)
74+
% Converts coordinates of a point in physical dimension to image index
75+
% First element is column index, second element is row index, both are
76+
% given in floating point and no rounding is performed.
77+
doc = currentDoc(obj);
78+
img = doc.Image;
79+
spacing = img.Spacing(1:2);
80+
origin = img.Origin(1:2);
81+
index = (point - origin) ./ spacing + 1;
82+
end
83+
84+
end % methods
85+
86+
end % classdef

0 commit comments

Comments
 (0)