Skip to content

Commit 4b05d7e

Browse files
authored
Merge pull request #240 from thewtex/is-pixel-inside-region-python
ENH: Add IsPixelInsideRegion Python example
2 parents 3e52c05 + b9b630b commit 4b05d7e

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

src/Core/Common/CreateASize/Documentation.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ Create a Size
77
Synopsis
88
--------
99

10-
1110
Create a itk::Size, which represents the size of a region in an itk::Image.
1211

13-
1412
Results
1513
-------
1614

1715
Output::
16+
1817
[0, 0]
1918
[1, 2]
2019

src/Core/Common/IsPixelInsideRegion/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ install( TARGETS IsPixelInsideRegion
1313
COMPONENT Runtime
1414
)
1515

16-
install( FILES Code.cxx CMakeLists.txt
16+
install( FILES Code.cxx Code.py CMakeLists.txt
1717
DESTINATION share/ITKExamples/Code/Core/Common/IsPixelInsideRegion
1818
COMPONENT Code
1919
)
2020

2121
enable_testing()
2222
add_test( NAME IsPixelInsideRegionTest
2323
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/IsPixelInsideRegion )
24+
25+
if(ITK_WRAP_PYTHON)
26+
add_test(NAME IsPixelInsideRegionPython
27+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
28+
)
29+
endif()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
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+
import itk
18+
19+
Dimension = 2
20+
21+
SizeType = itk.Size[Dimension]
22+
size = SizeType()
23+
size.Fill(3)
24+
25+
IndexType = itk.Index[Dimension]
26+
start = IndexType()
27+
start.Fill(0)
28+
29+
RegionType = itk.ImageRegion[Dimension]
30+
region = RegionType(start, size)
31+
32+
testPixel1 = IndexType()
33+
testPixel1[0] = 1
34+
testPixel1[1] = 1
35+
36+
testPixel2 = IndexType()
37+
testPixel2[0] = 6
38+
testPixel2[1] = 6
39+
40+
print(testPixel1, end=" ")
41+
if region.IsInside(testPixel1):
42+
print("Inside")
43+
else:
44+
print("Outside")
45+
46+
print(testPixel2, end=" ")
47+
if region.IsInside(testPixel2):
48+
print("Inside")
49+
else:
50+
print("Outside")

src/Core/Common/IsPixelInsideRegion/Documentation.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ Output::
2525
Code
2626
----
2727

28+
Python
29+
......
30+
31+
.. literalinclude:: Code.py
32+
:language: python
33+
:lines: 1, 16-
34+
2835
C++
2936
...
3037

0 commit comments

Comments
 (0)