Skip to content

Commit

Permalink
ENH: Rescale to original range.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntustison committed Feb 17, 2024
1 parent c1ceed2 commit 618af96
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions R/histogramEqualizeImage.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ histogramEqualizeImage <- function(
breakVector <- seq( min( imageArray ), max( imageArray ), length.out = numberOfHistogramBins )
imageHistogram <- hist( imageVector, breaks = breakVector, plot = FALSE )
cdf <- cumsum( imageHistogram$density )
cdf <- cdf * ( numberOfHistogramBins - 1 ) / tail( cdf, n = 1 )
cdf <- cdf / tail( cdf, n = 1 )
imageArrayEqualizedFlat <- approx( imageHistogram$breaks[1:( numberOfHistogramBins - 1 )], cdf, imageVector, method = "linear", rule = 2 )
imageArrayEqualized = array( data = imageArrayEqualizedFlat$y, dim = dim( imageArray ) )
imageEqualized <- as.antsImage( imageArrayEqualized, reference = image )
imageArrayEqualized <- array( data = imageArrayEqualizedFlat$y, dim = dim( imageArray ) )
imageArrayEqualized <- ( imageArrayEqualized - min( imageArrayEqualized ) ) / ( max( imageArrayEqualized ) - min( imageArrayEqualized ) )
imageArrayEqualized <- imageArrayEqualized * ( max( imageArray ) - min( imageArray ) ) + min( imageArray )

return( imageEqualized )
return( as.antsImage( imageArrayEqualized, reference = image ) )
}

0 comments on commit 618af96

Please sign in to comment.