File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -816,6 +816,42 @@ def signed_distance(self):
816
816
dt = lambda x : scipy .ndimage .distance_transform_edt (x , sampling = sampling )
817
817
sdt = lambda x : dt (1 - x ) - dt (x )
818
818
return stack ([self .new (sdt (self .framed_data [..., i ])) for i in range (self .nframes )])
819
+
820
+ def extract_sub_images (self , sub_shape ):
821
+ """
822
+ Extract a list of sub images from the FramedImage with shape 'sub_shape'
823
+
824
+ Parameters
825
+ ----------
826
+ sub_shape : array like
827
+ Shape to be given to the sub images that are extracted
828
+
829
+ Returns
830
+ -------
831
+ list of FramedImages
832
+ sub images
833
+ """
834
+
835
+ # ensure valid shape for the sub images
836
+ if len (sub_shape ) != self .basedim :
837
+ raise ValueError ('Image and sub_shape must have same dimensions' )
838
+
839
+ img_shape = np .array (self .shape )
840
+ sub_shape = np .array (sub_shape )
841
+
842
+ # find number of slices to take in each dim
843
+ to_slice = img_shape // sub_shape
844
+
845
+ # get the the 'ordered pairs' of all croppings
846
+ indices = [len (range (int (to_slice [d ]))) for d in range (len (img_shape ))]
847
+
848
+ sub_volumes = []
849
+ # extract all the sub images
850
+ for idx in np .ndindex (* indices ):
851
+ slices = tuple (slice (sub_shape [d ] * idx [d ], sub_shape [d ] * (idx [d ] + 1 )) for d in range (len (sub_shape )))
852
+ sub_volumes .append (self [slices ])
853
+
854
+ return sub_volumes
819
855
820
856
821
857
class Slice (FramedImage ):
You can’t perform that action at this time.
0 commit comments