Skip to content

Commit

Permalink
add resizing options for pre-registration matching
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaHess12 committed Apr 29, 2021
1 parent 08edf1b commit 52b4bee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions HDIprep/hdi_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def ApplyMask(self):
hdi_imp.hdi.data.processed_image = tmp_im

# Add function for exporting UMAP nifti image
def ExportNifti1(self, output_dir, padding=None):
def ExportNifti1(self, output_dir, padding=None, target_size=None):
"""Exporting hyperspectral images resulting from UMAP and
spatially mapping UMAP, or exporting processed histology images. Both of these
conditions cant be true. One or the other will be exported, and it will be
Expand Down Expand Up @@ -1154,11 +1154,11 @@ def ExportNifti1(self, output_dir, padding=None):
# Otherwise export the image
else:
# Export the original image
ExportNifti(hdi_imp.hdi.data.image, im_name, padding)
ExportNifti(hdi_imp.hdi.data.image, im_name, padding, target_size)
# Otherwise export the processed image
else:
# Use utils export nifti function
ExportNifti(hdi_imp.hdi.data.processed_image, im_name, padding)
ExportNifti(hdi_imp.hdi.data.processed_image, im_name, padding, target_size)
# Add exported file names to class object -- connect input file name with the exported name
connect_dict.update({f: im_name})

Expand Down
6 changes: 5 additions & 1 deletion HDIprep/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pandas as pd
import nibabel as nib
from pathlib import Path
from skimage.transform import resize

# Define function
def CreateHyperspectralImage(embedding, array_size, coordinates, scale=True):
Expand Down Expand Up @@ -84,7 +85,7 @@ def CreateHyperspectralImageRectangular(embedding, array_size, coordinates, scal
# Return the hyperspectral image
return im

def ExportNifti(image, filename, padding=None):
def ExportNifti(image, filename, padding=None, target_size=None):
"""This function will export your final images to nifti format for image
registration with elastix.
Expand All @@ -100,6 +101,9 @@ def ExportNifti(image, filename, padding=None):

# Print update
print("Exporting nifti image stack...")
# Check to see if resizing
if target_size is not None:
image = resize(im,target_size)
# Check to see if padding
if padding is not None:
image = np.pad(
Expand Down

0 comments on commit 52b4bee

Please sign in to comment.