@@ -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
0 commit comments