From ddd3d76300dc19cc250f513ac700dc66c573db07 Mon Sep 17 00:00:00 2001 From: Nick Tustison Date: Fri, 29 Mar 2024 14:07:14 -0700 Subject: [PATCH] COMP: Issue with min/max not registering as ANTsRCore::min/max --- R/cerebellumMorphology.R | 7 ++----- R/chexnet.R | 4 ++-- R/deepFlash.R | 8 ++++---- R/histogramWarpImageIntensities.R | 2 +- R/histology.R | 4 ++-- R/hypothalamusSegmentation.R | 2 +- R/mriModalityClassification.R | 3 +-- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/R/cerebellumMorphology.R b/R/cerebellumMorphology.R index 3ab7ff87..51dd47b1 100644 --- a/R/cerebellumMorphology.R +++ b/R/cerebellumMorphology.R @@ -89,8 +89,7 @@ cerebellumMorphology <- function( t1, cerebellumMask = NULL, t1TemplateBrainMask <- antsImageRead( getANTsXNetData( "magetTemplateBrainMask" ) ) t1TemplateBrain <- t1Template * t1TemplateBrainMask t1CerebellumTemplate <- antsImageRead( getANTsXNetData( "magetCerebellumTemplate" ) ) - t1CerebellumTemplate <- ( ( t1CerebellumTemplate - min( t1CerebellumTemplate ) ) / - ( max( t1CerebellumTemplate ) - min( t1CerebellumTemplate ) ) ) + t1CerebellumTemplate <- iMath( t1CerebellumTemplate, "Normalize" ) cerebellumxTemplateXfrm <- getANTsXNetData( "magetCerebellumxTemplate0GenericAffine" ) # spatial priors are in the space of the cerebellar template. First three are @@ -262,9 +261,7 @@ cerebellumMorphology <- function( t1, cerebellumMask = NULL, t1PreprocessedInCerebellumSpace <- t1PreprocessedInCerebellumSpace * t1PreprocessedMaskInCerebellumSpace } - t1PreprocessedInCerebellumSpace <- - ( t1PreprocessedInCerebellumSpace - min( t1PreprocessedInCerebellumSpace ) ) / - ( max( t1PreprocessedInCerebellumSpace ) - min( t1PreprocessedInCerebellumSpace ) ) + t1PreprocessedInCerebellumSpace <- iMath( t1PreprocessedInCerebellumSpace, "Normalize" ) batchX <- array( data = 0, dim = c( 2, imageSize, channelSize ) ) batchX[1,,,,1] <- as.array( padOrCropImageToSize( t1PreprocessedInCerebellumSpace, imageSize ) ) diff --git a/R/chexnet.R b/R/chexnet.R index ae53aebc..43501cca 100644 --- a/R/chexnet.R +++ b/R/chexnet.R @@ -54,8 +54,8 @@ checkXrayLungOrientation <- function( image, antsxnetCacheDirectory = antsxnetCacheDirectory ) model$load_weights( weightsFileName ) - imageMin <- min( resampledImage ) - imageMax <- max( resampledImage ) + imageMin <- ANTsRCore::min( resampledImage ) + imageMax <- ANTsRCore::max( resampledImage ) normalizedImage <- antsImageClone( resampledImage ) normalizedImage <- ( normalizedImage - imageMin ) / ( imageMax - imageMin ) diff --git a/R/deepFlash.R b/R/deepFlash.R index 9c65216c..0a351bac 100644 --- a/R/deepFlash.R +++ b/R/deepFlash.R @@ -191,12 +191,12 @@ deepFlash <- function( t1, t2 = NULL, doPreprocessing = TRUE, direction <- antsGetDirection( tmpCropped ) t1TemplateRoiLeft <- cropIndices( t1Template, lowerBoundLeft, upperBoundLeft ) - t1TemplateRoiLeft <- ( t1TemplateRoiLeft - min( t1TemplateRoiLeft ) ) / ( max( t1TemplateRoiLeft ) - min( t1TemplateRoiLeft ) ) * 2.0 - 1.0 + t1TemplateRoiLeft <- iMath( t1TemplateRoiLeft, "Normalize" ) * 2.0 - 1.0 t2TemplateRoiLeft <- NULL if( ! is.null( t2Template ) ) { t2TemplateRoiLeft <- cropIndices( t2Template, lowerBoundLeft, upperBoundLeft ) - t1TemplateRoiLeft <- ( t2TemplateRoiLeft - min( t2TemplateRoiLeft ) ) / ( max( t2TemplateRoiLeft ) - min( t2TemplateRoiLeft ) ) * 2.0 - 1.0 + t2TemplateRoiLeft <- iMath( t2TemplateRoiLeft, "Normalize" ) * 2.0 - 1.0 } labelsRight <- labels[seq.int( 3, length( labels ), by = 2)] @@ -209,12 +209,12 @@ deepFlash <- function( t1, t2 = NULL, doPreprocessing = TRUE, originRight <- antsGetOrigin( tmpCropped ) t1TemplateRoiRight <- cropIndices( t1Template, lowerBoundRight, upperBoundRight ) - t1TemplateRoiRight <- ( t1TemplateRoiRight - min( t1TemplateRoiRight ) ) / ( max( t1TemplateRoiRight ) - min( t1TemplateRoiRight ) ) * 2.0 - 1.0 + t1TemplateRoiRight <- iMath( t1TemplateRoiRight, "Normalize" ) * 2.0 - 1.0 t2TemplateRoiRight <- NULL if( ! is.null( t2Template ) ) { t2TemplateRoiRight <- cropIndices( t2Template, lowerBoundRight, upperBoundRight ) - t2TemplateRoiRight <- ( t2TemplateRoiRight - min( t2TemplateRoiRight ) ) / ( max( t2TemplateRoiRight ) - min( t2TemplateRoiRight ) ) * 2.0 - 1.0 + t2TemplateRoiRight <- iMath( t2TemplateRoiRight, "Normalize" ) * 2.0 - 1.0 } ################################ diff --git a/R/histogramWarpImageIntensities.R b/R/histogramWarpImageIntensities.R index 348643c1..8e5cf44a 100644 --- a/R/histogramWarpImageIntensities.R +++ b/R/histogramWarpImageIntensities.R @@ -111,7 +111,7 @@ histogramWarpImageIntensities <- function( image, transformedArray[indices] <- intensities + xfrm } transformedImage <- as.antsImage( transformedArray, reference = image ) * - ( max( image ) - min( image ) ) + min( image ) + ( ANTsRCore::max( image ) - ANTsRCore::min( image ) ) + ANTsRCore::min( image ) return( transformedImage ) } diff --git a/R/histology.R b/R/histology.R index a1c3a849..8c3f8d12 100644 --- a/R/histology.R +++ b/R/histology.R @@ -178,7 +178,7 @@ allenEx5BrainExtraction <- function( image, view = c( "coronal", "sagittal" ), } else { slice <- imageChannels[[i]] } - if( max( slice ) > min( slice ) ) + if( ANTsRCore::max( slice ) > ANTsRCore::min( slice ) ) { sliceResampled <- resampleImage( slice, resampledImageSize, useVoxels = TRUE, interpType = 0 ) sliceArray <- as.array( sliceResampled ) @@ -347,7 +347,7 @@ allenHistologyBrainMask <- function( image, } else { slice <- imageChannels[[i]] } - if( max( slice ) > min( slice ) ) + if( ANTsRCore::max( slice ) > ANTsRCore::min( slice ) ) { sliceResampled <- resampleImage( slice, resampledImageSize, useVoxels = TRUE, interpType = 0 ) sliceArray <- as.array( sliceResampled ) diff --git a/R/hypothalamusSegmentation.R b/R/hypothalamusSegmentation.R index 858b42ce..1308cb36 100644 --- a/R/hypothalamusSegmentation.R +++ b/R/hypothalamusSegmentation.R @@ -89,7 +89,7 @@ hypothalamusSegmentation <- function( t1, # ################################ - t1Warped <- ( t1Warped - min( t1Warped ) ) / ( max( t1Warped ) - min( t1Warped ) ) + t1Warped <- iMath( t1Warped, "Normalize" ) ################################ # diff --git a/R/mriModalityClassification.R b/R/mriModalityClassification.R index da9b45b6..8d8d02ad 100644 --- a/R/mriModalityClassification.R +++ b/R/mriModalityClassification.R @@ -60,8 +60,7 @@ mriModalityClassification <- function( image, center = centerOfMassTemplate, translation = centerOfMassImage - centerOfMassTemplate ) image <- applyAntsrTransformToImage( xfrm, image, template ) - - image <- ( image - min( image ) ) / ( max( image ) - min( image ) ) + image <- iMath( image, "Normalize" ) ################################ #