Skip to content

Commit 22f432f

Browse files
committed
ENH: Add CalculateImageMoments and fix cookiecutter and other issues.
DOC: Changed cookiecutter to put Python link first DOC: Changed CalculateImageMoments to put Python link first BUG: Removed extraneous lines in CMakeLists refering to output_image ENH: Changed cookiecutter to use argparse for print_usage ENH: Changed CalculateImageMoments to use argparse for print_usage BUG: Fixed IterateRegionWithAccessToIndexWithoutWriteAccess/Code.cxx to use defined region instead of LargestPossibleRegion (Closes #270) Added ellipse.png.sha512 so that the image would render. Fixed whitespace and syntax issues with .rst.
1 parent 2571627 commit 22f432f

File tree

8 files changed

+75
-61
lines changed

8 files changed

+75
-61
lines changed

Utilities/CookieCutter/{{cookiecutter.example_name}}/Code.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
import sys
1818
import itk
1919

20-
if len(sys.argv) != 3:
21-
print("Usage: " + sys.argv[0] + "<InputFileName> "
22-
"<OutputFileName>")
23-
sys.exit(1)
24-
25-
parser = argparse.ArgumentParser(description='{{ cookiecutter.example_title }}.')
26-
parser.add_argument('input_image')
27-
parser.add_argument('output_image')
20+
parser = argparse.ArgumentParser(description="{{ cookiecutter.example_title }}.")
21+
parser.add_argument("input_image")
22+
parser.add_argument("output_image")
2823
args = parser.parse_args()
2924

3025
input_image = itk.imread(args.input_image)
3126

32-
output_image = itk.itkHelpers.camel_to_snake_case({{ cookiecutter.class_name }})(input_image)
27+
output_image = itk.itkHelpers.camel_to_snake_case({{cookiecutter.class_name}})(
28+
input_image
29+
)
3330

3431
itk.imwrite(output_image, args.output_image)

Utilities/CookieCutter/{{cookiecutter.example_name}}/Documentation.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ Results
3232
Code
3333
----
3434

35+
Python
36+
......
37+
38+
.. literalinclude:: Code.py
39+
:language: python
40+
:lines: 1,16-
41+
3542
C++
3643
...
3744

3845
.. literalinclude:: Code.cxx
3946
:language: c++
4047
:lines: 18-
4148

42-
Python
43-
......
44-
45-
.. literalinclude:: Code.py
46-
:language: python
47-
:lines: 1,16-
4849

4950

5051
Classes demonstrated

src/Core/Common/IterateRegionWithAccessToIndexWithoutWriteAccess/Code.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ main(int argc, char * argv[])
5353
region.SetSize(regionSize);
5454
region.SetIndex(regionIndex);
5555

56-
itk::ImageRegionConstIteratorWithIndex<ImageType> imageIterator(image, image->GetLargestPossibleRegion());
56+
itk::ImageRegionConstIteratorWithIndex<ImageType> imageIterator(image, region);
5757

5858
while (!imageIterator.IsAtEnd())
5959
{

src/Filtering/ImageStatistics/CalculateImageMoments/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ add_test( NAME CalculateImageMomentsTest
2929

3030
if( ITK_WRAP_PYTHON )
3131
find_package(PythonInterp REQUIRED)
32-
string( REPLACE . "Python." output_image "${output_image}" )
3332
add_test( NAME CalculateImageMomentsTestPython
3433
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
3534
${input_image}

src/Filtering/ImageStatistics/CalculateImageMoments/CalculateEllipseMoments.ipynb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "revolutionary-headquarters",
6+
"metadata": {},
7+
"source": [
8+
"# Calculate Image Moments of an Ellipse\n",
9+
"\n",
10+
"Image moments can be used to determine the center of gravity or average pixel location of a binary object as well as the orientation of an object according to its axes of variation.\n",
11+
"\n",
12+
"The interactive plot below demonstrates how to calculate the image moments of an ellipse-defined mask."
13+
]
14+
},
315
{
416
"cell_type": "code",
5-
"execution_count": 9,
6-
"id": "protecting-hobby",
17+
"execution_count": 1,
18+
"id": "amino-atlantic",
719
"metadata": {},
820
"outputs": [],
921
"source": [
@@ -15,14 +27,14 @@
1527
},
1628
{
1729
"cell_type": "code",
18-
"execution_count": 32,
19-
"id": "dried-demographic",
30+
"execution_count": 2,
31+
"id": "domestic-jenny",
2032
"metadata": {},
2133
"outputs": [
2234
{
2335
"data": {
2436
"application/vnd.jupyter.widget-view+json": {
25-
"model_id": "12ddf6ab0ad54db19849293d0d20c252",
37+
"model_id": "9460aeb87fea499c90c4e301da10ddce",
2638
"version_major": 2,
2739
"version_minor": 0
2840
},
@@ -84,7 +96,7 @@
8496
{
8597
"cell_type": "code",
8698
"execution_count": null,
87-
"id": "several-label",
99+
"id": "seasonal-sandwich",
88100
"metadata": {},
89101
"outputs": [],
90102
"source": []

src/Filtering/ImageStatistics/CalculateImageMoments/Code.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
import itk
1919
import argparse
2020

21-
if len(sys.argv) != 2:
22-
print("Usage: " + sys.argv[0] + "<InputFileName>")
23-
print("Prints image moment information from binary image.")
24-
sys.exit(1)
25-
2621
parser = argparse.ArgumentParser(description="Calculate Image Moments.")
2722
parser.add_argument("input_image")
2823

src/Filtering/ImageStatistics/CalculateImageMoments/Documentation.rst

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,57 @@
1+
:name: CalculateImageMoments
2+
13
Calculate Image Moments
24
================================
35

46
.. index::
57
single: ImageMomentsCalculator
68

9+
.. toctree::
10+
:maxdepth: 1
11+
12+
CalculateEllipseMoments.ipynb
13+
714
Synopsis
815
--------
916

1017

1118
Calculate image moments from binary images and an interactive ellipse.
1219

13-
1420
Results
1521
-------
1622

17-
.. figure:: ellipse.mha
18-
:scale: 50%
23+
Input Image
24+
25+
.. figure:: ellipse.png
1926
:alt: Input image
2027

21-
Input Image
22-
::
23-
Output
24-
ImageMomentsCalculator (000002037138BE90)
25-
RTTI typeinfo: class itk::ImageMomentsCalculator<class itk::Image<unsigned short,2> >
26-
Reference Count: 1
27-
Modified Time: 249
28-
Debug: Off
29-
Object Name:
30-
Observers:
31-
none
32-
Image: 000002037138FDD0
33-
Valid: 1
34-
Zeroth Moment about origin: 153
35-
First Moment about origin: [30, 50]
36-
Second Moment about origin: 15.0458 -8.8366
37-
-8.8366 15.0458
38-
39-
Center of Gravity: [30, 50]
40-
Second central moments: 15.0458 -8.8366
41-
-8.8366 15.0458
42-
43-
Principal Moments: [950, 3654]
44-
Principal axes: 0.707107 0.707107
45-
-0.707107 0.707107
28+
4629
::
4730

31+
Output
32+
ImageMomentsCalculator (000002037138BE90)
33+
RTTI typeinfo: class itk::ImageMomentsCalculator<class itk::Image<unsigned short,2> >
34+
Reference Count: 1
35+
Modified Time: 249
36+
Debug: Off
37+
Object Name:
38+
Observers:
39+
none
40+
Image: 000002037138FDD0
41+
Valid: 1
42+
Zeroth Moment about origin: 153
43+
First Moment about origin: [30, 50]
44+
Second Moment about origin: 15.0458 -8.8366
45+
-8.8366 15.0458
46+
47+
Center of Gravity: [30, 50]
48+
Second central moments: 15.0458 -8.8366
49+
-8.8366 15.0458
50+
51+
Principal Moments: [950, 3654]
52+
Principal axes: 0.707107 0.707107
53+
-0.707107 0.707107
54+
4855

4956
Jupyter Notebook
5057
-----------------
@@ -55,19 +62,21 @@ Jupyter Notebook
5562
Code
5663
----
5764

65+
Python
66+
......
67+
68+
.. literalinclude:: Code.py
69+
:language: python
70+
:lines: 1,16-
71+
5872
C++
5973
...
6074

6175
.. literalinclude:: Code.cxx
6276
:language: c++
6377
:lines: 18-
6478

65-
Python
66-
......
6779

68-
.. literalinclude:: Code.py
69-
:language: python
70-
:lines: 1,16-
7180

7281

7382
Classes demonstrated
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
faafd547a568d258dc916d18058f6dae75ef3fe31e83ee500e71a9a253eb502961e362f18cfd5c5a4e2edab78341184a891016abee4718b286d564c24afedf35

0 commit comments

Comments
 (0)