Skip to content

Commit 0b9e002

Browse files
committed
Image3DIsosurface: add support for label images (through the regionIsosurfaces method)
1 parent 070f175 commit 0b9e002

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

ImageM/+imagem/+actions/+view/Image3DIsosurface.m

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ function run(obj, frame) %#ok<INUSL>
3737

3838
% get handle to current doc
3939
doc = currentDoc(frame);
40+
img = doc.Image;
4041

4142
% check image size
42-
img = doc.Image;
4343
if size(img, 3) == 1
4444
return;
4545
end
4646

4747
% creates a new dialog, and populates it with some fields
4848
gd = imagem.gui.GenericDialog('3D Isosurface');
4949

50-
addNumericField(gd, 'Isosurface Value', 50, 2);
50+
if ~isLabelImage(img)
51+
addNumericField(gd, 'Isosurface Value', 50, 2);
52+
end
5153
addNumericField(gd, 'Smoothing Radius (voxels)', 2, 0);
5254
addCheckBox(gd, 'Reverse Z-axis', false);
5355
addCheckBox(gd, 'Rotate Ox', false);
@@ -59,7 +61,10 @@ function run(obj, frame) %#ok<INUSL>
5961
return;
6062
end
6163

62-
isosurfaceValue = getNextNumber(gd);
64+
% parse user inputs
65+
if ~isLabelImage(img)
66+
isosurfaceValue = getNextNumber(gd);
67+
end
6368
smoothRadius = getNextNumber(gd);
6469
reverseZAxis = getNextBoolean(gd);
6570
rotateXAxis = getNextBoolean(gd);
@@ -70,27 +75,40 @@ function run(obj, frame) %#ok<INUSL>
7075
img = rotate90(img, 'x', 1);
7176
end
7277

73-
if smoothRadius > 0
74-
disp('% smoothing...');
75-
siz = floor(smoothRadius * 2) + 1;
76-
img = gaussianFilter(img, siz, smoothRadius);
77-
end
78-
79-
80-
% eventually rotate image around X-axis
81-
if rotateXAxis
82-
img = flip(rotate90(img, 'x', 1), 2);
83-
end
84-
85-
% create figure
78+
% create figure
8679
hf = figure(); hold on;
8780
set(hf, 'renderer', 'opengl');
88-
isosurface(img, isosurfaceValue);
81+
82+
if ~isLabelImage(img)
83+
% smooth grayscale / intensities
84+
if smoothRadius > 0
85+
disp('% smoothing...');
86+
siz = floor(smoothRadius * 2) + 1;
87+
img = gaussianFilter(img, siz, smoothRadius);
88+
end
89+
90+
% compute isosurface of grayscale/intensity values
91+
isosurface(img, isosurfaceValue);
92+
93+
else
94+
% For label images, call the specific regionIsosurfaces
95+
[meshes, labels] = regionIsosurfaces(img, 'smoothRadius', smoothRadius);
96+
97+
% display each mesh with color specified by colormap of doc
98+
colors = doc.ColorMap;
99+
for iLabel = 1:length(meshes)
100+
label = labels(iLabel);
101+
p = patch(meshes{iLabel});
102+
color = colors(label, :);
103+
set(p, 'FaceColor', color, 'LineStyle', 'none');
104+
end
105+
end
89106

90107
% setup display
91108
axis equal;
92109
axis(physicalExtent(img));
93110
axis('vis3d'); view(3);
111+
set(hf, 'Name', sprintf('%s-isosurface', img.Name));
94112
light;
95113

96114
if rotateXAxis || reverseZAxis
@@ -110,8 +128,11 @@ function run(obj, frame) %#ok<INUSL>
110128
end
111129

112130
% add history
113-
% string = sprintf('showOrthoSlices(%s, [%d %d %d]);\n', doc.Tag, pos);
114-
string = sprintf('isosurface(%s, %g);\n', doc.Tag, isosurfaceValue);
131+
if ~isLabelImage(img)
132+
string = sprintf('isosurface(%s, %g);\n', doc.Tag, isosurfaceValue);
133+
else
134+
string = sprintf('%% isosurface of label image %s\n', doc.Tag);
135+
end
115136
addToHistory(frame, string);
116137
end
117138

ImageM/+imagem/+app/ImageDoc.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
% Display range info are managed within the ImageViewer class.
2828

2929
% Look-up table (colormap) used for displaying the image.
30+
% Uses 256 values for grayscale/intensity images, and label number for
31+
% label images.
3032
% If empty -> no lut
3133
ColorMap = [];
3234

ImageM/+imagem/+app/ImagemDoc.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
% ImagemDoc
88
%
99
% See also
10-
%
10+
% ImageDoc, TableDoc
1111

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

0 commit comments

Comments
 (0)