Skip to content

Commit a46f681

Browse files
committed
update brush tool
1 parent 88f1845 commit a46f681

File tree

4 files changed

+90
-25
lines changed

4 files changed

+90
-25
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
classdef SetBrushValue < imagem.gui.Action
2+
% Change the value of the brush.
3+
%
4+
% Class SetBrushValue
5+
%
6+
% Example
7+
% SetBrushValue
8+
%
9+
% See also
10+
%
11+
12+
% ------
13+
% Author: David Legland
14+
15+
% Created: 2020-01-30, using Matlab 7.9.0.529 (R2009b)
16+
% Copyright 2011 INRA - Cepia Software Platform.
17+
18+
19+
%% Properties
20+
properties
21+
end % end properties
22+
23+
24+
%% Constructor
25+
methods
26+
function obj = SetBrushValue()
27+
end
28+
29+
end % end constructors
30+
31+
32+
methods
33+
function run(obj, frame) %#ok<INUSL,INUSD>
34+
disp('set brush value');
35+
36+
answer = inputdlg(...
37+
'Enter the brush value:', ...
38+
'Input Brush size', ...
39+
1, {num2str(frame.Gui.App.BrushValue)});
40+
41+
if isempty(answer)
42+
return;
43+
end
44+
45+
size = str2double(answer{1});
46+
if isnan(size)
47+
errordlg('Could not understand brush value');
48+
end
49+
50+
frame.Gui.App.BrushValue = size;
51+
end
52+
53+
end
54+
55+
end % end classdef
56+

ImageM/+imagem/+app/ImagemApp.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929
% The size (diameter) of the brush (in pixels).
3030
BrushSize = 3;
31-
31+
32+
% The value used to draw the brush
33+
BrushValue = 255;
34+
3235
% History of user commands, as a cell array of strings.
3336
History = cell(0, 1);
3437
end

ImageM/+imagem/+gui/FrameMenuBuilder.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ function buildImageFrameMenu(obj, hf)
151151

152152

153153
settingsMenu = addMenu(obj, imageMenu, 'Settings', 'Separator', 'on');
154-
addMenuItem(obj, settingsMenu, SetDefaultConnectivity(), 'Set Connectivity');
155154
addMenuItem(obj, settingsMenu, SetBrushSize(), 'Set Brush Size');
155+
addMenuItem(obj, settingsMenu, SetBrushValue(), 'Set Brush Value');
156+
addMenuItem(obj, settingsMenu, SetDefaultConnectivity(), 'Set Connectivity', 'Separator', 'on');
156157

157158

158159
% View Menu Definition

ImageM/+imagem/+tools/Brush.m

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
% ------
1313
% Author: David Legland
14-
% e-mail: david.legland@inra.fr
14+
% e-mail: david.legland@inrae.fr
1515
% Created: 2011-11-21, using Matlab 7.9.0.529 (R2009b)
1616
% Copyright 2011 INRA - Cepia Software Platform.
1717

1818
%% Properties
1919
properties
2020
ButtonPressed = false;
2121

22-
% the current drawing 'color', initialized to white
23-
Color = 255;
22+
% % The current drawing 'value', initialized to white
23+
% Value = 255;
2424

2525
PreviousPoint;
2626
end
@@ -56,11 +56,7 @@ function onMouseMoved(obj, hObject, eventdata) %#ok<INUSD>
5656
function processCurrentPosition(obj)
5757
doc = obj.Viewer.Doc;
5858
img = doc.Image;
59-
60-
if ~isGrayscaleImage(img)
61-
return;
62-
end
63-
59+
6460
point = get(obj.Viewer.Handles.ImageAxis, 'CurrentPoint');
6561
coord = round(pointToIndex(obj, point(1, 1:2)));
6662

@@ -69,13 +65,21 @@ function processCurrentPosition(obj)
6965
if any(coord < 1) || any(coord > dim([1 2]))
7066
return;
7167
end
68+
69+
% indices of Z, C and T dimensions
70+
iz = 1;
71+
if isa(obj.Viewer, 'imagem.gui.Image3DSliceViewer')
72+
iz = obj.Viewer.SliceIndex;
73+
end
74+
ic = 1:channelNumber(img);
75+
it = 1; % not managed for the moment
7276

7377
if ~isempty(obj.PreviousPoint)
7478
% mouse moved from a previous position
75-
drawBrushLine(obj, coord, obj.PreviousPoint);
79+
drawBrushLine(obj, coord, obj.PreviousPoint, iz, ic, it);
7680
else
7781
% respond to mouse button pressed, mouse hasn't moved yet
78-
drawBrush(obj, coord);
82+
drawBrush(obj, coord, iz, ic, it);
7983
end
8084

8185
obj.PreviousPoint = coord;
@@ -96,16 +100,16 @@ function processCurrentPosition(obj)
96100
index = (point - origin) ./ spacing + 1;
97101
end
98102

99-
function drawBrushLine(obj, coord1, coord2)
103+
function drawBrushLine(obj, coord1, coord2, iz, ic, it)
100104
[x, y] = imagem.tools.Brush.intline(coord1(1), coord1(2), coord2(1), coord2(2));
101105

102106
% iterate on current line
103107
for i = 1 : length(x)
104-
drawBrush(obj, [x(i) y(i)]);
108+
drawBrush(obj, [x(i) y(i)], iz, ic, it);
105109
end
106110
end
107111

108-
function drawBrush(obj, coord)
112+
function drawBrush(obj, coord, iz, ic, it)
109113
doc = obj.Viewer.Doc;
110114

111115
% brush size in each direction
@@ -119,25 +123,26 @@ function drawBrush(obj, coord)
119123
y1 = max(coord(2)-bs1, 1);
120124
x2 = min(coord(1)+bs2, dim(1));
121125
y2 = min(coord(2)+bs2, dim(2));
122-
126+
123127
% iterate on brush pixels
124-
for i = x1:x2
125-
for j = y1:y2
126-
doc.Image(i, j) = obj.Color;
128+
for ix = x1:x2
129+
for iy = y1:y2
130+
doc.Image.Data(ix, iy, iz, ic, it) = obj.Viewer.Gui.App.BrushValue;
127131
end
128132
end
129133
end
130134
end % methods
131135

132136
methods (Static, Access = private)
133137
function [x, y] = intline(x1, y1, x2, y2)
134-
%INTLINE Integer-coordinate line drawing algorithm.
135-
% [X, Y] = INTLINE(X1, X2, Y1, Y2) computes an
138+
% Integer-coordinate line drawing algorithm.
139+
%
140+
% [X, Y] = intline(X1, X2, Y1, Y2) computes an
136141
% approximation to the line segment joining (X1, Y1) and
137142
% (X2, Y2) with integer coordinates. X1, X2, Y1, and Y2
138-
% should be integers. INTLINE is reversible; that is,
139-
% INTLINE(X1, X2, Y1, Y2) produces the same results as
140-
% FLIPUD(INTLINE(X2, X1, Y2, Y1)).
143+
% should be integers. intline is reversible; that is,
144+
% intline(X1, X2, Y1, Y2) produces the same results as
145+
% FLIPUD(intline(X2, X1, Y2, Y1)).
141146
%
142147
% Function adapted from the 'strel' function of matlab.
143148
%
@@ -190,7 +195,7 @@ function drawBrush(obj, coord)
190195
methods
191196
function b = isActivable(obj)
192197
doc = obj.Viewer.Doc;
193-
b = ~isempty(doc) && ~isempty(doc.Image) && isScalarImage(doc.Image);
198+
b = ~isempty(doc) && ~isempty(doc.Image);
194199
end
195200
end
196201

0 commit comments

Comments
 (0)