From c747731156fbe11d05403c52d91930f545031c92 Mon Sep 17 00:00:00 2001 From: jbeckwith Date: Wed, 7 Aug 2024 10:50:23 +0100 Subject: [PATCH] Updated Chopping Code --- src/IOFunctions.py | 45 ++++++++++++-------- src/__pycache__/IOFunctions.cpython-310.pyc | Bin 4932 -> 5043 bytes 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/IOFunctions.py b/src/IOFunctions.py index 0777ef1..fd2a60e 100644 --- a/src/IOFunctions.py +++ b/src/IOFunctions.py @@ -105,14 +105,16 @@ def get_identical_element_indices(arr): k = 0 l = 0 maxval = 0 + for polygon in exterior_polys: coords_array = np.array(polygon.exterior.coords) min_x = int(np.min(coords_array[:, 0])) min_y = int(np.min(coords_array[:, 1])) max_x = int(np.max(coords_array[:, 0])) max_y = int(np.max(coords_array[:, 1])) - maxval += len(np.arange(min_x, max_x, multi_tiff_pixel_size)) - maxval += len(np.arange(min_y, max_y, multi_tiff_pixel_size)) + maxval += len(np.arange(min_x, max_x, multi_tiff_pixel_size)) * len( + np.arange(min_y, max_y, multi_tiff_pixel_size) + ) for polygon in exterior_polys: @@ -144,8 +146,9 @@ def get_identical_element_indices(arr): x_grid, y_grid = np.meshgrid(x_cor_list, y_cor_list) corr = np.vstack([x_grid.ravel(), y_grid.ravel()]).T mask_total = np.zeros_like(corr[:, 0], dtype=bool) - for i in np.arange(len(exterior_polys)): - mask = polygon_paths[i].contains_points(corr) + for polygon in exterior_polys: + polygon_path = mpl_path.Path(polygon.exterior.coords) + mask = polygon_path.contains_points(corr) mask_total = np.logical_or(mask_total, mask) mask_total = np.reshape( mask_total, (multi_tiff_pixel_size, multi_tiff_pixel_size) @@ -168,22 +171,28 @@ def get_identical_element_indices(arr): new_image_path, format="TIFF", tiffinfo=tags_tosave ) - new_image_path = os.path.join( + mask_image_path = os.path.join( temp_directory, f"image_mask_{x_cor}_{y_cor}.tiff" ) - img_pil = Image.fromarray(mask_total) - tags_tosave = copy(self.example_tags) - tags_tosave[296] = 3 - tags_tosave[262] = 1 - tags_tosave[282] = 1e-3 / pixel_size - tags_tosave[283] = 1e-3 / pixel_size - tags_tosave[270] = "Python=3.10.12f\nunit=micron\n" - tags_tosave[256] = img_pil.width - tags_tosave[257] = img_pil.height - tags_tosave[278] = img_pil.height - tags_tosave[279] = img_pil.height * img_pil.width - img_pil.save( - new_image_path, format="TIFF", tiffinfo=tags_tosave + mask_pil = Image.fromarray(mask_total) + masktags_tosave = copy(self.example_tags) + masktags_tosave[296] = 3 + del masktags_tosave[258] + masktags_tosave[259] = 1 + masktags_tosave[262] = 1 + del masktags_tosave[273] + del masktags_tosave[50838] + del masktags_tosave[50839] + masktags_tosave[282] = 1e-3 / pixel_size + masktags_tosave[283] = 1e-3 / pixel_size + masktags_tosave[270] = "Python=3.10.12f\nunit=micron\n" + masktags_tosave[277] = 1 + del masktags_tosave[256] + del masktags_tosave[257] + del masktags_tosave[278] + del masktags_tosave[279] + mask_pil.save( + mask_image_path, format="TIFF", tiffinfo=masktags_tosave ) l += 1 print( diff --git a/src/__pycache__/IOFunctions.cpython-310.pyc b/src/__pycache__/IOFunctions.cpython-310.pyc index eef89e21da649b3d35105fac9b11bd91f5441a45..634d2ff0d4fb766c785aa4d4f6518542170817cd 100644 GIT binary patch delta 771 zcmYjOO=uHA6rPveZkCvAlV;PTY4hJUzs*no(uC$9dK5uCcq*khw$0j_)GShALJmDB zg+gIbK@pORN1-fu^Clid!E-Kp^yJBdC+nMumhNM|`R0A!oA=oHFmI=|mdE2F`2DHd z+lTQp?K3EP=i%K_(f$TW(CR2%!F3H+=aW4y{Q|gU$z#WHQ#0ND8J1+TOd3c>ppz=; z#twe7z;$v88_&>mXyud?T(xd0K`2?<%F{9zHv(P18R$Q%q=>hA)Q~76v-l6 zrYW{+4V{Tz)y(v>tb*gOU9_)Z`x4zRZuhhw;BmKG zdyjWo4>sFd=B~BvEhL8H`&*s+o6Y^LoqHlXR7IlQ+#5;O6K@fs);sU6-=RVHU+CZl z*SSl!O1|P96*O>x7i3UDKG!7$CUDmz7oOc1DylqmbSR*lD>BzzLRU~#c@|^j{eM!d Nx4uVkYR^r?;4ixPzPbPa delta 649 zcmbu5zi-n(6vyxRoWwHe$u_AI$8k)PG(Q?>oBo2K5(AxCI#)vK385^g)T$Vs#gK)e zm5PpmUqiygfP}yj6C)%10W6S_KL8|{%Co6ZCD^#9r~BOZ`|j@PC7t(eaeHRQWV9aK zcysef_*#5`-1+@GyGzLw8Xz{vIY)Voa{pao@oxaz>Q(NpigQluGK)hDBM}wHHEduD z`Gk)kRrh}2>=rwQokJ>q>RpLDQ58GL%M6<%E$(7FbK7b+e}6f>9toTs!34J0jupFD zL)T;D7A{X9ULk)T2e>lP;=wWOeOG>=32)Waf`4x{>JEF@m#!=yY4KXLfNad?SmV34^1@iX)? z_K2@bw#|AA$roeFA)kCMegxP^UW%`vo?CtO(`tgN0{fN?0;;FsLIq4sJ+c>T4#^hi uV1Ry7;(2gr*SQY)6O*f{U9RVTD;nu0H>j>iVSt&1r2^*w4wHvY2)_U}T%?i!