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""" A SimpleITK example demonstrating image viewing using the Show function
20 and an external application. """
21
22import sys
23import SimpleITK as sitk
24
25grid_image = sitk.GridSource(
26 outputPixelType=sitk.sitkUInt16,
27 size=(512, 512),
28 sigma=(0.1, 0.1),
29 gridSpacing=(20.0, 20.0),
30)
31
32# Procedural interface, using the default image viewer (Fiji/ImageJ) or
33# any viewer specified by the SITK_SHOW_COMMAND environment variable.
34sitk.Show(grid_image, title="grid using Show function", debugOn=True)
35
36# Object oriented interface:
37image_viewer = sitk.ImageViewer()
38image_viewer.SetTitle("grid using ImageViewer class")
39
40# Use the default image viewer.
41image_viewer.Execute(grid_image)
42
43# Change viewer, and display again.
44image_viewer.SetApplication("/Applications/ITK-SNAP.app/Contents/MacOS/ITK-SNAP")
45image_viewer.Execute(grid_image)
46
47# Change the viewer command, (use ITK-SNAP's -z option to open the image in
48# zoomed mode)
49image_viewer.SetCommand("/Applications/ITK-SNAP.app/Contents/MacOS/ITK-SNAP -z 2")
50image_viewer.Execute(grid_image)
51
52sys.exit(0)
Display an image in an external viewer (Fiji by default)
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.
void SITKIO_EXPORT Show(const Image &image, const std::string &title="", const bool debugOn=ProcessObject::GetGlobalDefaultDebug())