Hi Lee,
Many thanks for finding the time to look at this:
program output:
*** tile.shape=(1186, 1912, 3)
*** tile.shape[0] = 1186, tile.shape[1] = 1912
*** n = 14, s = 84, p = 10 before halving
type(input_image)=<class 'itk.itkImagePython.itkImageRGBUC2'>
type(reference_image)=<class 'itk.itkImagePython.itkImageRGBUC2'>
( 0, 0) ( 5: 89, 5: 89) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 1) ( 5: 89, 89: 173) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 2) ( 5: 89, 173: 257) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 3) ( 5: 89, 257: 341) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 4) ( 5: 89, 341: 425) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 5) ( 5: 89, 425: 509) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 6) ( 5: 89, 509: 593) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 7) ( 5: 89, 593: 677) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 8) ( 5: 89, 677: 761) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0, 9) ( 5: 89, 761: 845) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0,10) ( 5: 89, 845: 929) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0,11) ( 5: 89, 929:1013) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0,12) ( 5: 89, 1013:1097) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 0,13) ( 5: 89, 1097:1181) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 1, 0) ( 89: 173, 5: 89) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 1, 1) ( 89: 173, 89: 173) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 1, 2) ( 89: 173, 173: 257) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 1, 3) ( 89: 173, 257: 341) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 1, 4) ( 89: 173, 341: 425) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
( 1, 5) ( 89: 173, 425: 509) <class 'itk.itkImagePython.itkImageRGBUC2'>
patch_npa.shape=(84, 84, 3)
Segmentation fault: 11
$ /usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
warnings.warn('resource_tracker: There appear to be %d ‘
Python script producing above:
# Import itk, which includes itk-spcn.
import itk
#from itkwidgets import view # JRS
# Fetch input images, if we don have them already.
input_image_filename = 'Easy1.png'
reference_image_filename = 'Hard.png'
# The pixels are RGB triplets of unsigned char. The images are 2 dimensional.
PixelType = itk.RGBPixel[itk.UC]
ImageType = itk.Image[PixelType, 2]
# Invoke the functional, eager interface for ITK
input_image = itk.imread(input_image_filename, PixelType)
reference_image = itk.imread(reference_image_filename, PixelType)
# try looping over slices of input_image
tile = input_image
n = 14 # make patch/sliced grid 14x14
print(f' *** tile.shape={tile.shape}')
l = min(tile.shape[0],tile.shape[1]) # side of sliced grid
s = int(l/n) # side of a slice
p = l - n*s
print(f' *** tile.shape[0] = {tile.shape[0]}, tile.shape[1] = {tile.shape[1]}')
print(f' *** n = {n}, s = {s}, p = {p:.3g} before halving')
p = int(p/2) # index offset
print(f' type(input_image)={type(input_image)}')
print(f' type(reference_image)={type(reference_image)}\n')
for i in range(n): # x patch index
I = p + i*s # patch top left in x
for j in range(n): # y patch index
J = p + j*s # patch top left in y
patch_npa = tile[J:J+s,I:I+s,:]
patch_itk_inp = itk.GetImageFromArray(patch_npa.copy(), is_vector=True)
input_image = patch_itk_inp
patch_CN = itk.structure_preserving_color_normalization_filter(
input_image,
reference_image,
color_index_suppressed_by_hematoxylin=0,
color_index_suppressed_by_eosin=1
)
print(f' ({i:2},{j:2}) ({I:4}:{I+s:4}, {J:4}:{J+s:4}) {type(patch_CN)}')
print(f'\t patch_npa.shape={patch_npa.shape}')
Jon R. Sauer
jon.sauer@gmail.com
Acton, MA, USA 01720
+1 303.579.3009