SimpleITK  
ImageViewing/ImageViewing.py
1 # =========================================================================
2 #
3 # Copyright NumFOCUS
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0.txt
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # =========================================================================
18 
19 import sys
20 import SimpleITK as sitk
21 
22 grid_image = sitk.GridSource(
23  outputPixelType=sitk.sitkUInt16,
24  size=(512, 512),
25  sigma=(0.1, 0.1),
26  gridSpacing=(20.0, 20.0),
27 )
28 
29 # Procedural interface, using the default image viewer (Fiji/ImageJ) or
30 # any viewer specified by the SITK_SHOW_COMMAND environment variable.
31 sitk.Show(grid_image, title="grid using Show function", debugOn=True)
32 
33 # Object oriented interface:
34 image_viewer = sitk.ImageViewer()
35 image_viewer.SetTitle("grid using ImageViewer class")
36 
37 # Use the default image viewer.
38 image_viewer.Execute(grid_image)
39 
40 # Change viewer, and display again.
41 image_viewer.SetApplication(
42  "/Applications/ITK-SNAP.app/Contents/MacOS/ITK-SNAP"
43 )
44 image_viewer.Execute(grid_image)
45 
46 # Change the viewer command, (use ITK-SNAP's -z option to open the image in
47 # zoomed mode)
48 image_viewer.SetCommand(
49  "/Applications/ITK-SNAP.app/Contents/MacOS/ITK-SNAP -z 2"
50 )
51 image_viewer.Execute(grid_image)
52 
53 sys.exit(0)
itk::simple::GridSource
Image GridSource(PixelIDValueEnum outputPixelType=itk::simple::sitkFloat32, std::vector< unsigned int > size=std::vector< unsigned int >(3, 64), std::vector< double > sigma=std::vector< double >(3, 0.5), std::vector< double > gridSpacing=std::vector< double >(3, 4.0), std::vector< double > gridOffset=std::vector< double >(3, 0.0), double scale=255.0, std::vector< double > origin=std::vector< double >(3, 0.0), std::vector< double > spacing=std::vector< double >(3, 1.0), std::vector< double > direction=std::vector< double >(), std::vector< bool > whichDimensions=std::vector< bool >(3, true))
Generate an n-dimensional image of a grid.
itk::simple::Show
void SITKIO_EXPORT Show(const Image &image, const std::string &title="", const bool debugOn=ProcessObject::GetGlobalDefaultDebug())
itk::simple::ImageViewer
Display an image in an external viewer (Fiji by default)
Definition: sitkImageViewer.h:50