R/replaceEmptyImageDimensions.R
replaceEmptyImageDimensions-methods.Rd
Simple wrapper for subsetting an image with indices, dropping empty dimensions.
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
# S4 method for nifti
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
# S4 method for character
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
# S4 method for factor
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
# S4 method for list
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
# S4 method for array
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
# S4 method for anlz
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
# S4 method for ANY
replaceEmptyImageDimensions(
img,
inds,
target_dim,
value = 0,
reorient = FALSE,
...
)
replace_empty_dim(img, ...)
img | image, nifti object, or array |
---|---|
inds | indices of subset from |
target_dim | Original dimension from which the data was subset, the final dimension of the output |
value | value to replace in the image where outside the indices |
reorient | Should image be reoriented if a filename? |
... | not used |
Object of class nifti
or array
if nifti
is not supplied
replace_empty_dim
is a shorthand for
replaceEmptyImageDimensions
with all the same arguments.
dims = rep(10, 3)
arr = array(rnorm(prod(dims)), dim = dims)
arr[,,10] = 0
nim = oro.nifti::nifti(arr)
rnifti = RNifti::asNifti(nim)
timg = tempimg(nim)
limg = list(factor(timg, timg))
inds = getEmptyImageDimensions(nim)
inds_arr = getEmptyImageDimensions(arr)
testthat::expect_equal(inds, inds_arr)
out = applyEmptyImageDimensions(nim, inds = inds)
result = replaceEmptyImageDimensions(out, inds = inds,
target_dim = dim(nim))
testthat::expect_equal(array(result, dim = dim(result)),
array(nim, dim = dim(nim)))
replace_empty_dim(out, inds = inds,
target_dim = dim(nim))
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 2 (UINT8)
#> Bits per Pixel : 8
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
target_dim = dim(nim)
arr = array(out, dim = dim(out))
nim = oro.nifti::nifti(arr)
rnifti = RNifti::asNifti(nim)
timg = tempimg(nim)
limg = list(factor(timg), factor(timg))
func = function(...) replaceEmptyImageDimensions(...,
target_dim = target_dim, inds = inds)
func(arr)
#> , , 1
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -1.455054580 0.35371673 0.07154236 -0.3193709 0.02427047 0.5103241
#> [2,] 1.244562895 0.19686123 1.58742119 0.4533303 1.63998671 -1.4463722
#> [3,] -0.431947066 1.02408529 0.42775193 0.1873734 2.53711506 -1.1493737
#> [4,] 0.006869276 -0.95397535 0.30824859 0.8134706 0.03088726 -1.4521959
#> [5,] 0.124551049 0.46929952 0.12165626 -1.1491983 0.16289618 -0.4164989
#> [6,] -0.409628630 -0.08416000 -1.31702404 -1.0023346 -0.69680745 1.7292613
#> [7,] 0.563413643 -1.13043686 -0.90964805 1.2703415 1.86248487 -0.5368687
#> [8,] 1.606958115 -0.23048749 -0.54785093 0.2252663 0.39478395 1.0725307
#> [9,] -1.001951673 -0.03326209 -0.78616488 -1.4288808 -0.83123964 -0.4284239
#> [10,] 0.509325898 -1.00303535 0.36185981 -0.6365831 -1.57671783 1.0081221
#> [,7] [,8] [,9] [,10]
#> [1,] -1.051405262 0.7098586 -0.05959747 -0.60817957
#> [2,] 0.416472333 2.1391790 0.09257406 0.08729448
#> [3,] 0.795446589 0.7059825 -0.40940108 1.47582898
#> [4,] 1.468349517 2.4028356 0.06400144 2.34133665
#> [5,] 0.156620959 -0.4591719 -0.81036270 -2.00802022
#> [6,] -0.006058787 -0.2766064 -0.08615954 -0.62321155
#> [7,] 0.517898064 -0.9119570 0.26396333 0.45494052
#> [8,] -0.812061260 -0.2531641 -1.30783185 -0.39179293
#> [9,] 0.518137819 -1.3449507 1.08618610 0.01164354
#> [10,] -0.537654786 -0.7576484 1.02516845 -0.22323923
#>
#> , , 2
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -1.1881977 1.0527729 1.0889794 -1.85225453 0.9035049 1.11012114
#> [2,] -0.1129823 1.7923427 -0.1529200 0.17886939 -0.6828178 -0.76889484
#> [3,] -0.5682077 1.3812497 0.2618635 -0.33534945 -1.5420894 0.51082975
#> [4,] -2.6758843 0.6547846 0.8161795 0.17493318 0.5704716 2.01506105
#> [5,] -0.1931324 1.8957390 -2.2658790 -0.30195751 -1.1879210 2.03768449
#> [6,] 0.6878320 0.2604489 -1.0405127 0.40090148 -0.3856099 1.03677475
#> [7,] 1.6041010 -1.1271386 -0.9421653 -0.20154014 -1.3251098 0.11319751
#> [8,] 1.2065154 -1.1053940 1.1129344 -0.65037435 -0.3007082 0.39803419
#> [9,] 0.7408385 -0.6207683 0.6230657 -0.03151802 -0.2564991 0.04374652
#> [10,] 0.2412313 -1.5297891 2.0115363 1.25338847 -0.9327200 -0.79216637
#> [,7] [,8] [,9] [,10]
#> [1,] -0.5306151 -0.97944377 1.24687092 0.50273909
#> [2,] 1.5013916 -2.44939342 0.94643533 -0.15489422
#> [3,] 0.5265423 0.08224266 0.03250499 0.06409767
#> [4,] 0.2649481 1.04455525 0.77708653 -0.38239364
#> [5,] 1.9072938 -0.02051408 0.61964722 0.22093071
#> [6,] 0.6965592 -0.04664942 -0.42253318 0.61874107
#> [7,] -0.3079923 -0.23556611 0.45962001 -0.12445678
#> [8,] -0.4679756 1.05143444 0.04175007 -1.31256709
#> [9,] 0.1887640 -0.02817788 0.39453714 0.53982854
#> [10,] 0.6334116 0.65241695 0.18921904 -0.49662052
#>
#> , , 3
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.4992706 1.8105003 1.7317790 -0.7256319 0.16506090 0.96311673
#> [2,] 1.5413355 0.4431730 0.9454940 -0.6159109 -0.02200758 -0.16745445
#> [3,] 0.3332295 0.2911019 -1.1046548 2.1653067 0.15235486 -0.01628852
#> [4,] 0.6121035 0.1262117 -0.6744610 0.2728470 -0.87114813 -1.01825699
#> [5,] 1.4316895 1.3823779 -0.4644514 1.1543353 -0.70857401 0.94071342
#> [6,] 0.4250808 0.8391622 -0.4032082 -0.7304815 1.53018378 1.23723877
#> [7,] -0.3443959 -0.3164566 0.8193320 -0.4207352 0.02138028 2.15164625
#> [8,] -1.4601540 1.4859747 -0.0506727 0.6966880 1.53632188 1.71415512
#> [9,] -0.3490282 0.2041833 0.4179846 -0.2027448 1.28202247 -1.29284657
#> [10,] 0.5599105 -1.5298153 1.2943860 -0.4230289 -1.42325665 -0.01051857
#> [,7] [,8] [,9] [,10]
#> [1,] -0.5272350 0.10614626 0.71690753 0.02593722
#> [2,] 0.1372085 0.69900265 -1.47485985 2.18515253
#> [3,] 0.8287229 -0.29571966 1.22615917 0.05955112
#> [4,] -1.4802022 -0.17792223 -0.53122065 0.45730238
#> [5,] 0.2247072 1.11493411 -0.47062977 0.71937104
#> [6,] 2.1975729 -0.39776691 0.02939022 -0.86743881
#> [7,] -1.3161987 0.57320752 0.87280681 -1.17669159
#> [8,] 0.5473619 -0.11214127 0.17217967 -1.58503386
#> [9,] 0.4968773 -0.03357408 1.05499902 -0.67067399
#> [10,] -1.0109621 -0.64952330 0.39225523 0.50163486
#>
#> , , 4
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.7569363 0.23181578 -1.42030814 -1.0131786 0.09069140 1.2952797
#> [2,] 0.3293909 -1.49087428 0.59737861 -0.8192975 -1.94611293 -0.3675500
#> [3,] -0.2524970 -0.64903904 -0.89998871 -2.2646897 -1.50398722 0.5009510
#> [4,] -1.9168587 -1.10981936 -0.85742711 -0.4662584 -0.81818943 0.7685881
#> [5,] -1.6387344 0.41460318 0.23871171 0.7867338 0.05001088 -0.1606394
#> [6,] 2.3518878 0.25431100 -0.19758229 -1.2773689 1.18198583 1.1021699
#> [7,] 1.0282100 -0.13607694 0.43542967 0.3600824 -0.94377232 1.1855639
#> [8,] 1.0707755 0.09618894 -0.91671112 -0.5994894 1.40489169 2.7107141
#> [9,] 0.6221745 0.62916217 0.26218225 0.9481267 0.32294062 -0.8289441
#> [10,] 0.3389947 0.21053934 -0.02587299 0.2553048 -1.28084423 1.6459819
#> [,7] [,8] [,9] [,10]
#> [1,] 0.19540155 0.9287718 -1.2957209 -0.12371039
#> [2,] -1.16742215 1.3375707 -0.1237218 0.93711805
#> [3,] -0.05391972 1.3683238 -0.3113328 -0.29018693
#> [4,] 0.44526475 0.2856060 -0.8876510 -0.34751109
#> [5,] -0.19981214 -0.9316736 0.3636128 -2.08374632
#> [6,] 2.08750229 -1.8798861 -0.9980481 0.04995877
#> [7,] 0.56768373 -1.1275208 0.1988657 1.05093318
#> [8,] 0.97833587 -0.5635056 0.7736851 -0.53214346
#> [9,] 1.06955283 1.5372260 -0.9375740 0.43439886
#> [10,] -1.33864753 2.2657733 0.6591651 0.57742638
#>
#> , , 5
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.3340847 -0.47839733 0.062361970 -2.7446681 0.52590224 -0.455748320
#> [2,] -1.0937484 -1.67642880 -1.187390958 -0.7568704 -1.14775923 -0.482840630
#> [3,] 0.5267008 -0.71261046 1.107737823 2.4030814 -0.61950055 0.325126009
#> [4,] 1.4596793 -2.12264899 -0.591649590 0.2069463 0.11634167 -0.415286281
#> [5,] -1.5715444 -0.28461099 0.013069869 -0.4280330 -0.10247828 -2.088269076
#> [6,] -0.3207743 0.31242187 0.006429538 0.2945591 -0.05045989 -1.276997569
#> [7,] -0.1319609 1.47476142 0.495695987 -0.3628210 0.80396312 0.705057989
#> [8,] -1.1674531 -1.79778625 -1.669791719 0.4017748 -0.20649869 0.761163346
#> [9,] 0.7071350 0.04535347 0.313628301 -0.6792686 0.35107070 -0.008795716
#> [10,] 2.1065044 -0.09897743 -1.207543332 -0.6634182 1.31339052 0.751957318
#> [,7] [,8] [,9] [,10]
#> [1,] 0.3576183 -1.7474201 -0.1290164 -0.5448815
#> [2,] -0.1007290 -0.6752444 0.5754221 -0.4234069
#> [3,] -3.1071551 -0.8821889 1.4448029 0.4725368
#> [4,] -0.5911817 0.5482732 -0.7879075 -0.5579543
#> [5,] -0.4727720 0.3078159 2.3952406 -1.1444477
#> [6,] 1.5757802 0.3440338 0.4627291 -1.1226469
#> [7,] 1.0819392 -0.2986614 -0.5794908 -2.9766191
#> [8,] -0.5326359 0.1151944 1.8417568 0.8252340
#> [9,] -0.3495917 0.8766826 0.3647542 -1.2243138
#> [10,] 0.7802174 -0.6140345 0.7731505 -0.1597625
#>
#> , , 6
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.49008969 -0.15053023 -0.2918350 0.77314751 -0.7237965 0.8573577
#> [2,] 0.17027911 -0.03517459 -1.7830337 0.83304872 -0.1766338 2.3585250
#> [3,] 2.43416961 2.24243576 -0.5717317 0.28213158 -1.3344011 -0.4783181
#> [4,] 1.53144564 -0.81226181 0.8943840 0.66376281 0.7332155 -1.1898079
#> [5,] 0.93576548 0.83912504 1.2723487 0.56345449 0.1185545 0.2595749
#> [6,] -0.31839170 -0.28107608 -0.1561187 0.04947085 0.5747443 0.2452351
#> [7,] 0.22385618 0.55410851 0.0124521 0.26415393 -1.3955379 1.3316413
#> [8,] 0.17636531 -0.99348139 1.6717181 -0.21036877 0.6452110 -1.3349314
#> [9,] 0.25466418 -0.35074812 1.2718399 -0.93225528 2.1386482 0.4419720
#> [10,] -0.03550015 -1.92762488 1.8169393 0.96179297 -0.9561849 0.3372861
#> [,7] [,8] [,9] [,10]
#> [1,] 1.29887051 0.1463710 -1.34848475 -1.18576423
#> [2,] -0.76561989 -1.2726794 -1.22557615 1.84957340
#> [3,] 0.35427462 -1.0071398 -0.70895511 1.53508687
#> [4,] -1.14510411 -0.2631664 -0.34863477 0.04627948
#> [5,] -0.31863482 -0.9272148 1.84518490 2.09506299
#> [6,] 0.32797741 1.2076712 -1.58655846 -0.10803716
#> [7,] 0.07357561 -0.3638285 -0.39167108 -1.76655519
#> [8,] -0.40141701 -0.1253106 -1.71697238 1.03887240
#> [9,] 0.38359712 -1.9178788 0.98995620 0.41868034
#> [10,] -0.15602225 1.0468060 -0.05712006 -1.05339707
#>
#> , , 7
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.80717572 -0.9559509 -0.1339389 -0.07250340 -0.7684241 1.50180364
#> [2,] 2.05893747 -1.3665463 -0.2892072 0.04965521 1.1194177 0.89680899
#> [3,] 1.16922127 -1.7002020 -0.5272672 -0.77354726 -0.5449733 0.71806944
#> [4,] -0.92963424 -0.7180965 0.9741718 0.59707532 0.3995474 0.67823953
#> [5,] -0.06352343 1.4851849 0.9269039 0.11253788 1.3212335 -0.04957667
#> [6,] 1.48826553 0.8640152 -0.1190803 2.29705152 -0.1882809 0.67564555
#> [7,] -0.97041022 0.9133272 -0.3861458 1.31480501 -0.3356406 0.83725412
#> [8,] -1.87020037 -0.3045679 0.2945031 -0.32648330 1.4314978 -0.76463145
#> [9,] 0.13938171 0.2194829 -1.1087276 -0.31362920 -0.6635175 0.32108703
#> [10,] -0.59777495 0.9592475 -0.7196336 0.64151639 -0.8885758 -0.59927477
#> [,7] [,8] [,9] [,10]
#> [1,] 1.7549956 1.4356027 0.67428087 0.64556997
#> [2,] -0.5938849 1.1442673 0.23704919 1.47709855
#> [3,] 0.7694620 -1.4370256 -0.19441836 0.65113671
#> [4,] 0.3002622 -0.6811661 0.43543572 1.62336714
#> [5,] -1.5562480 1.8159785 0.12622020 -0.31741374
#> [6,] -0.3652412 -0.6991435 -0.55522996 -0.08023316
#> [7,] -0.4957951 1.5924035 -1.18871493 -0.57528823
#> [8,] -0.3324609 0.5827755 -0.04586440 0.78028852
#> [9,] -0.6116663 -1.1093009 0.09425523 -0.20937815
#> [10,] -1.6002243 -0.1899066 -0.04916839 0.12266581
#>
#> , , 8
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -1.5146432 -1.3065609 -0.8045863 -0.9434039 1.3841188 1.3797009
#> [2,] 0.2581711 0.4990906 0.3907901 0.1937860 -0.1110652 0.4917970
#> [3,] 1.4651705 1.3745442 1.4953355 -0.7311602 -1.4844215 1.3530453
#> [4,] -0.8230433 0.1466588 -0.2688253 1.4245127 0.7691500 0.7405562
#> [5,] 0.6009811 -1.0917786 0.2540759 0.4079308 -0.3771784 1.2122432
#> [6,] 0.4390219 0.4273696 -1.1188412 -1.0974237 -0.5569089 -2.1202842
#> [7,] -0.7772843 -0.2795690 1.5623319 -1.2901528 -0.7153900 0.8619906
#> [8,] 0.2416839 1.3556785 0.2217997 -0.7785802 1.4664234 -1.3985367
#> [9,] 0.7596107 1.3100026 -0.4772420 1.8771030 -1.7189811 0.1548110
#> [10,] 0.2075074 1.9194441 -0.2528194 -0.4125729 -1.4346979 -0.3759687
#> [,7] [,8] [,9] [,10]
#> [1,] 0.4498960 0.19819180 0.7159927 0.05571068
#> [2,] 2.1339966 0.69271526 -0.6258043 -0.29894090
#> [3,] -0.3741952 0.54944628 -0.1851604 -0.47141896
#> [4,] -1.1087352 2.56167560 0.2349396 0.10177523
#> [5,] -0.3167730 1.52376399 -0.4018204 0.30541260
#> [6,] -1.8241358 -1.76100004 0.8608704 -0.32870547
#> [7,] 0.7875943 1.80548112 1.3261243 -0.74906144
#> [8,] -0.6177715 0.30321482 -0.7052881 0.48428491
#> [9,] -0.8905109 -0.05875313 0.4353782 -0.37781248
#> [10,] -1.7036590 -0.13541582 -0.1297981 -0.25170904
#>
#> , , 9
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0.50863054 -0.2785600 0.1853639 1.035753928 -0.2379940 -1.492592001
#> [2,] 0.26094999 1.8035886 0.6736343 -0.506279133 -0.9635595 -1.443982207
#> [3,] 1.10268696 0.2881722 0.7160490 0.123793618 0.8521400 0.007750606
#> [4,] -0.02354004 -0.2591317 0.9419739 -0.767850447 -0.6535666 1.189554014
#> [5,] -0.07665418 0.4152626 -2.1452858 0.190999226 0.4655283 1.508630715
#> [6,] 0.80993061 0.2762354 1.3586752 0.283432350 1.2731511 1.088447140
#> [7,] -1.71393793 0.7164279 1.9305554 0.615096443 -0.9301206 0.836477133
#> [8,] 1.97506810 -0.3792217 -2.3662059 0.009051521 1.6323792 -0.692637371
#> [9,] -0.86722296 1.1249605 -0.5164127 -1.865811875 0.2089707 0.202121029
#> [10,] 1.46681133 0.3504751 -2.0769421 0.314708871 -0.6687492 2.354131990
#> [,7] [,8] [,9] [,10]
#> [1,] -0.11800069 -0.5253340 -1.5412057 0.105614016
#> [2,] 0.17290862 0.4812531 0.6062028 -0.004874413
#> [3,] -0.58146029 -3.3530015 2.0309994 0.552347713
#> [4,] -0.29217344 0.7748936 -1.0493241 -0.454247446
#> [5,] -0.03135228 -0.9184700 -0.1405244 -0.293124351
#> [6,] 0.14268924 0.5966215 -1.1617610 1.952503960
#> [7,] -1.06650155 0.6887051 -1.0903865 -1.231156499
#> [8,] 0.19823349 0.1371217 0.9636350 -1.446009644
#> [9,] 0.57282572 0.9619742 -1.1751661 0.475657988
#> [10,] 0.41421520 -0.8929752 -2.6646905 0.062018035
#>
#> , , 10
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> [1,] 0 0 0 0 0 0 0 0 0 0
#> [2,] 0 0 0 0 0 0 0 0 0 0
#> [3,] 0 0 0 0 0 0 0 0 0 0
#> [4,] 0 0 0 0 0 0 0 0 0 0
#> [5,] 0 0 0 0 0 0 0 0 0 0
#> [6,] 0 0 0 0 0 0 0 0 0 0
#> [7,] 0 0 0 0 0 0 0 0 0 0
#> [8,] 0 0 0 0 0 0 0 0 0 0
#> [9,] 0 0 0 0 0 0 0 0 0 0
#> [10,] 0 0 0 0 0 0 0 0 0 0
#>
func(nim)
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 2 (UINT8)
#> Bits per Pixel : 8
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
func(rnifti)
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 8 (INT32)
#> Bits per Pixel : 32
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
func(timg)
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 16 (FLOAT32)
#> Bits per Pixel : 32
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
func(limg)
#> [[1]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 16 (FLOAT32)
#> Bits per Pixel : 32
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>
#> [[2]]
#> NIfTI-1 format
#> Type : nifti
#> Data Type : 16 (FLOAT32)
#> Bits per Pixel : 32
#> Slice Code : 0 (Unknown)
#> Intent Code : 0 (None)
#> Qform Code : 0 (Unknown)
#> Sform Code : 0 (Unknown)
#> Dimension : 10 x 10 x 10
#> Pixel Dimension : 1 x 1 x 1
#> Voxel Units : Unknown
#> Time Units : Unknown
#>