vignettes/xrayr.Rmd
xrayr.Rmd
Focus on chest radiography.
library( xrayr )
library( magrittr )
library( ANTsRCore )
#>
#> Attaching package: 'ANTsRCore'
#> The following object is masked from 'package:stats':
#>
#> var
#> The following objects are masked from 'package:base':
#>
#> all, any, apply, max, min, prod, range, sum
library( ANTsR )
Motion correction.
temp1 = resampleImage( ri(1), 4 )
temp2 = resampleImage( ri(2), 4 )
tarspace = makeImage( c( dim( temp1 ), 2 ) )
pdcr = mergeListToNDImage( tarspace, list( temp1, temp2 ) )
reg = timeSeriesMotionCorrect( temp1, pdcr )
Real data.
procedure would differ slightly in a pure testing context ie it would be iterated until convergence but ultimately should probably be replaced with convnets
################
library( ANTsR )
library( xrayr )
baseDir = "/mnt/c/Users/bavants/projects/kmXrayPilotData/superRes/lowres/"
id = "0070"
fns = Sys.glob( paste0( baseDir, "*", id, "*mhd" ) )
img = antsImageRead( fns[1] )
limg = splitNDImageToList( img )
mimgLow = list()
ww = c( 5, 1:4,6:8) # arbitrarily chosen
limg = limg[ ww[ -1 ] ] # some stuff nearby
for ( k in 1:length( limg ) ) {
# downsample by factor of X for training data
X = 2.7
hiSpc = antsGetSpacing( limg[[ k ]])
loSpc = hiSpc * X
moLo = resampleImage( limg[[ k ]], loSpc, useVoxels = F )
mimgLow[[ k ]] = moLo
}
# map time series
reg = timeSeriesMotionCorrect( tar, mimgLow )
ct = 1
wts = seq( from=-2, to=2, by=0.1 )
errs = rep( NA, length( wts ))
for ( wt in wts ) {
sup = timeSeriesSuperResolution( tar, reg, 'sharpen', param1 = wt )
print( paste( wt, MSE( tar, sup ) ) )
errs[ ct ] = MSE( tar, sup )
ct = ct + 1
}
plot( wts, errs )