<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Pythonic Syntactic Sugar <a href="https
Step1:  Let us begin by developing a convenient method for displaying images in our notebooks.
Step2:  Multi-dimension slice indexing
If you are familiar with numpy, sliced index then this should be cake for the SimpleITK image. The Python standard slice interface for 1-D object
Step3:  Cropping
Step4:  Flipping
Step5:  Slice Extraction
A 2D image can be extracted from a 3D one.
Step6:  Subsampling
Step7:  Mathematical Operators
Most python mathematical operators are overloaded to call the SimpleITK filter which does that same operation on a per-pixel basis. They can operate on a two images or an image and a scalar.
If two images are used then both must have the same pixel type. The output image type is usually the same.
As these operators basically call ITK filter, which just use raw C++ operators, care must be taken to prevent overflow, and divide by zero etc.
<table>
    <tr><td>Operators</td></tr>
    <tr><td>+</td></tr>
    <tr><td>-</td></tr>
    <tr><td>&#42;</td></tr>
    <tr><td>/</td></tr>
    <tr><td>//</td></tr>
    <tr><td>**</td></tr>
</table>
Step8:  Division Operators
All three Python division operators are implemented __floordiv__, __truediv__, and __div__.
The true division's output is a double pixel type.
See PEP 238 to see why Python changed the division operator in Python 3.
Bitwise Logic Operators
<table>
    <tr><td>Operators</td></tr>
    <tr><td>&</td></tr>
    <tr><td>|</td></tr>
    <tr><td>^</td></tr>
    <tr><td>~</td></tr>
</table>
Step9:  Comparative Operators
<table>
    <tr><td>Operators</td></tr>
    <tr><td>&gt;</td></tr>
    <tr><td>&gt;=</td></tr>
    <tr><td>&lt;</td></tr>
    <tr><td>&lt;=</td></tr>
    <tr><td>==</td></tr>
</table>
These comparative operators follow the same convention as the reset of SimpleITK for binary images. They have the pixel type of sitkUInt8 with values of 0 and 1.
Step10:  Amazingly make common trivial tasks really trivial
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rc("image", aspect="equal")
import SimpleITK as sitk
# Download data to work on
%run update_path_to_download_script
from downloaddata import fetch_data as fdata
Explanation: Pythonic Syntactic Sugar <a href="https://mybinder.org/v2/gh/InsightSoftwareConsortium/SimpleITK-Notebooks/master?filepath=Python%2F02_Pythonic_Image.ipynb"><img style="float: right;" src="https://mybinder.org/badge_logo.svg"></a>
The Image Basics Notebook was straight forward and closely follows ITK's C++ interface.
Sugar is great it gives your energy to get things done faster! SimpleITK has applied a generous about of syntactic sugar to help get things done faster too.
End of explanation
img = sitk.GaussianSource(size=[64] * 2)
plt.imshow(sitk.GetArrayViewFromImage(img))
img = sitk.GaborSource(size=[64] * 2, frequency=0.03)
plt.imshow(sitk.GetArrayViewFromImage(img))
def myshow(img):
    nda = sitk.GetArrayViewFromImage(img)
    plt.imshow(nda)
myshow(img)
Explanation: Let us begin by developing a convenient method for displaying images in our notebooks.
End of explanation
img[24, 24]
Explanation: Multi-dimension slice indexing
If you are familiar with numpy, sliced index then this should be cake for the SimpleITK image. The Python standard slice interface for 1-D object:
<table>
    <tr><td>Operation</td>  <td>Result</td></tr>
    <tr><td>d[i]</td>   <td>i-th item of d, starting index 0</td></tr>
    <tr><td>d[i:j]</td> <td>slice of d from i to j</td></tr>
    <tr><td>d[i:j:k]</td>   <td>slice of d from i to j with step k</td></tr>
</table>
With this convenient syntax many basic tasks can be easily done.
End of explanation
myshow(img[16:48, :])
myshow(img[:, 16:-16])
myshow(img[:32, :32])
Explanation: Cropping
End of explanation
img_corner = img[:32, :32]
myshow(img_corner)
myshow(img_corner[::-1, :])
myshow(
    sitk.Tile(
        img_corner,
        img_corner[::-1, ::],
        img_corner[::, ::-1],
        img_corner[::-1, ::-1],
        [2, 2],
    )
)
Explanation: Flipping
End of explanation
img = sitk.GaborSource(size=[64] * 3, frequency=0.05)
# Why does this produce an error?
myshow(img)
myshow(img[:, :, 32])
myshow(img[16, :, :])
Explanation: Slice Extraction
A 2D image can be extracted from a 3D one.
End of explanation
myshow(img[:, ::3, 32])
Explanation: Subsampling
End of explanation
img = sitk.ReadImage(fdata("cthead1.png"))
img = sitk.Cast(img, sitk.sitkFloat32)
myshow(img)
img[150, 150]
timg = img**2
myshow(timg)
timg[150, 150]
Explanation: Mathematical Operators
Most python mathematical operators are overloaded to call the SimpleITK filter which does that same operation on a per-pixel basis. They can operate on a two images or an image and a scalar.
If two images are used then both must have the same pixel type. The output image type is usually the same.
As these operators basically call ITK filter, which just use raw C++ operators, care must be taken to prevent overflow, and divide by zero etc.
<table>
    <tr><td>Operators</td></tr>
    <tr><td>+</td></tr>
    <tr><td>-</td></tr>
    <tr><td>&#42;</td></tr>
    <tr><td>/</td></tr>
    <tr><td>//</td></tr>
    <tr><td>**</td></tr>
</table>
End of explanation
img = sitk.ReadImage(fdata("cthead1.png"))
myshow(img)
Explanation: Division Operators
All three Python division operators are implemented __floordiv__, __truediv__, and __div__.
The true division's output is a double pixel type.
See PEP 238 to see why Python changed the division operator in Python 3.
Bitwise Logic Operators
<table>
    <tr><td>Operators</td></tr>
    <tr><td>&</td></tr>
    <tr><td>|</td></tr>
    <tr><td>^</td></tr>
    <tr><td>~</td></tr>
</table>
End of explanation
img = sitk.ReadImage(fdata("cthead1.png"))
myshow(img)
Explanation: Comparative Operators
<table>
    <tr><td>Operators</td></tr>
    <tr><td>&gt;</td></tr>
    <tr><td>&gt;=</td></tr>
    <tr><td>&lt;</td></tr>
    <tr><td>&lt;=</td></tr>
    <tr><td>==</td></tr>
</table>
These comparative operators follow the same convention as the reset of SimpleITK for binary images. They have the pixel type of sitkUInt8 with values of 0 and 1.
End of explanation
myshow(img > 90)
myshow(img > 150)
myshow((img > 90) + (img > 150))
Explanation: Amazingly make common trivial tasks really trivial
End of explanation
<END_TASK>