R/maskEmptyImageDimensions.R
maskEmptyImageDimensions-methods.Rd
Simple wrapper for replacing indices with a value
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
# S4 method for nifti
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
# S4 method for character
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
# S4 method for factor
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
# S4 method for list
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
# S4 method for array
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
# S4 method for anlz
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
# S4 method for ANY
maskEmptyImageDimensions(img, inds, reorient = FALSE, mask.value = 0, ...)
mask_empty_dim(img, ...)
img | image, nifti object, or array |
---|---|
inds | indices of subset from |
reorient | Should image be reoriented if a filename? |
mask.value | Value to replace voxels outside the mask. |
... | not used |
Object of class nifti
or array
if nifti
is not supplied
mask_empty_dim
is a shorthand for
maskEmptyImageDimensions
with all the same arguments.
set.seed(5)
dims = rep(10, 3)
arr = array(rnorm(prod(dims)), dim = dims)
arr[,,10] = 0
nim = oro.nifti::nifti(arr)
inds = getEmptyImageDimensions(nim)
inds_arr = getEmptyImageDimensions(arr)
res = maskEmptyImageDimensions(nim, inds = inds, mask.value = NA)
res2 = maskEmptyImageDimensions(arr, inds = inds_arr, mask.value = NA)
testthat::expect_equal(array(res, dim = dim(res)),
array(res2, dim = dim(res2)))
set.seed(5)
dims = rep(10, 3)
arr = array(rnorm(prod(dims)), dim = dims)
arr[,,10] = 0
nim = oro.nifti::nifti(arr)
inds = getEmptyImageDimensions(nim)
rnifti = RNifti::asNifti(nim)
timg = tempimg(nim)
limg = list(factor(timg), factor(timg))
mask_empty_dim(nim, inds = inds)
#> 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 = function(...) maskEmptyImageDimensions(..., inds = inds)
func(arr)
#> , , 1
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.84085548 1.2276303 0.9005119 0.3159150 1.55006037 1.46324856
#> [2,] 1.38435934 -0.8017795 0.9418694 1.1096942 -0.80242318 0.18772610
#> [3,] -1.25549186 -1.0803926 1.4679619 2.2154606 -0.07457892 1.02202286
#> [4,] 0.07014277 -0.1575344 0.7067611 1.2171036 1.89566795 -0.59183483
#> [5,] 1.71144087 -1.0717600 0.8190089 1.4792218 -0.45656894 -0.11220066
#> [6,] -0.60290798 -0.1389861 -0.2934818 0.9515738 0.56222336 -0.92495309
#> [7,] -0.47216639 -0.5973131 1.4185891 -1.0095326 -0.88700851 0.75330480
#> [8,] -0.63537131 -2.1839668 1.4987738 -2.0004727 -0.46024458 -0.11260907
#> [9,] -0.28577363 0.2408173 -0.6570821 -1.7621859 -0.72432849 -0.06409093
#> [10,] 0.13810822 -0.2593554 -0.8527954 -0.1426081 -0.06921116 0.23327529
#> [,7] [,8] [,9] [,10]
#> [1,] -1.1365828 -0.20409732 0.49841617 0.92604713
#> [2,] 0.8548304 -0.22561419 -1.74230249 -1.06241117
#> [3,] -0.5783704 0.34702845 0.97552910 0.55703387
#> [4,] 0.4963615 0.03236784 -0.02408287 0.90073058
#> [5,] -0.7600579 0.41353129 0.67568448 0.98994568
#> [6,] -0.3413863 -0.15534848 -0.71030961 0.38360809
#> [7,] -2.1023291 0.97348539 2.38723265 -0.34658381
#> [8,] -0.3017023 0.12109014 -0.47343201 -0.54018925
#> [9,] -1.2723834 0.18917369 -0.07577256 -0.18255559
#> [10,] -0.2796661 -0.56288507 -0.52184006 -0.05929965
#>
#> , , 2
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -1.99538697 -0.95290496 1.1708564 1.3485491 -0.79599499 0.9460885
#> [2,] 1.13531128 1.62237939 0.8848449 -1.9785283 -0.02935340 0.7517709
#> [3,] 0.67579457 2.60014202 -1.3178886 -1.2409506 2.18023570 -0.5173768
#> [4,] 0.20848326 0.13964851 -1.6432509 -0.1040391 0.95741847 0.8083360
#> [5,] -0.05784564 -1.35071967 1.0592504 0.7329730 -0.30504863 -0.6145352
#> [6,] 0.89381141 0.79893102 0.2900836 0.4556796 -0.41840334 1.2382589
#> [7,] -0.22886538 -1.55499584 -0.4000335 0.2880795 0.09995405 -0.3380951
#> [8,] -1.96565265 0.46372006 1.2430958 -1.0736909 -0.22980962 1.1963664
#> [9,] -0.75351045 0.05242956 -1.3664105 0.6487425 -1.41521488 -0.4433184
#> [10,] 1.28015162 -0.20203180 -1.4414133 0.2991623 -0.39259886 0.1861149
#> [,7] [,8] [,9] [,10]
#> [1,] -2.62134481 -1.44014752 2.1816467 0.66753870
#> [2,] 2.24625462 0.14376888 -0.6837733 0.36623695
#> [3,] 0.09343168 -1.23458665 0.7500592 -0.51494299
#> [4,] 1.62728009 -1.75250121 0.9743826 0.45056824
#> [5,] -0.51091755 -0.03549629 -1.2644735 -0.18772038
#> [6,] -0.65938084 0.33203491 -0.2774214 1.33906937
#> [7,] -0.04019016 1.57228826 -0.1893987 0.81621918
#> [8,] -0.11869400 -1.06947057 -0.3840249 0.08220176
#> [9,] -0.01965686 0.91628652 0.7405880 -0.65086272
#> [10,] -0.48567849 -0.59499290 -1.1683384 0.72640902
#>
#> , , 3
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.1136782 1.2185331 0.21083288 -0.3819834 0.30438718 -0.25820706
#> [2,] -0.2951008 0.6291344 -0.03329921 0.9776881 -0.11749825 -0.26689944
#> [3,] 0.9891685 0.5277463 2.02519699 -0.5580409 -0.06008553 0.16415596
#> [4,] -0.7751318 -0.4722553 -0.37078675 -0.6264551 1.47093895 -0.39345895
#> [5,] 0.2758983 0.8237152 -1.57823445 -0.5304512 -1.47814761 -1.84373725
#> [6,] 0.4107816 -0.4277882 -0.12157195 1.8976216 -0.68361295 -1.54228827
#> [7,] 0.6111832 -0.1426439 -1.79667682 1.3955407 0.46054060 -0.58624036
#> [8,] 0.9365707 1.4187830 -0.47559154 -0.7460259 -0.18150193 -0.85213891
#> [9,] -0.3675417 0.4871339 -0.88410232 -0.3055731 -1.15881631 0.77832456
#> [10,] 0.7403768 0.6034415 -3.49805898 1.1696782 0.40901892 -0.03031707
#> [,7] [,8] [,9] [,10]
#> [1,] -1.45565758 -0.355740791 0.12515439 -0.21872403
#> [2,] 0.09378492 -0.985414318 -0.77243411 0.68259291
#> [3,] 0.98234922 -0.731170643 -1.01296612 0.52413002
#> [4,] -0.59671016 1.465324083 0.96691960 0.08054998
#> [5,] 0.07480485 1.858615318 -0.42332730 0.05378554
#> [6,] 2.19742943 0.003497027 -0.83159945 -0.73725899
#> [7,] 0.79502321 -1.343775245 1.39995727 0.96643806
#> [8,] -0.53894221 0.151294033 0.01701396 0.98430685
#> [9,] -1.60128318 0.290009125 1.84749695 0.18729094
#> [10,] -0.73137357 -0.122478328 -0.68633938 0.27298575
#>
#> , , 4
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.2101461 -0.86072563 -0.3635949 -1.12559665 -2.8849411 -2.110555073
#> [2,] 0.1886572 1.23863449 1.3746533 -0.21935925 -2.3346918 0.260676110
#> [3,] 1.9624987 0.76743575 0.2918957 -0.13430795 -1.7308910 0.945566826
#> [4,] 0.1387119 -1.08740911 0.7105917 -0.81802061 0.8250096 -0.619960620
#> [5,] -1.5786274 0.06750377 -0.9377609 0.47233416 -1.0450396 -0.009100739
#> [6,] -0.7970213 1.60514057 -1.1140631 -0.86925613 -0.8771934 0.520225423
#> [7,] 1.2243539 1.23222943 0.6343720 -1.33228834 -0.4003898 1.806258708
#> [8,] -0.3653336 -0.37911379 -0.2311929 0.07056287 -1.2681890 -1.912519898
#> [9,] -0.1625903 -1.34986658 -1.3681942 0.46409319 0.1385864 0.199282075
#> [10,] 0.5604792 0.36491810 -0.7549074 0.28915850 1.1835716 0.276484953
#> [,7] [,8] [,9] [,10]
#> [1,] -0.8362764 0.0898948 2.1160472 -0.4079171
#> [2,] 2.0295974 1.0049101 1.1886396 0.2013111
#> [3,] 0.4291060 -1.8729417 0.8952612 -0.7319475
#> [4,] 1.0639479 0.5247845 0.8685406 0.7291357
#> [5,] -0.6058231 -0.5146273 1.6561780 0.3266486
#> [6,] 1.0743730 1.2109326 1.4456360 -2.7078779
#> [7,] -0.7123476 -0.5127954 0.7446004 -0.5921389
#> [8,] -0.1788601 1.0906257 -0.6901902 0.5045437
#> [9,] 0.4997600 0.4918449 -0.7914118 -1.5226971
#> [10,] -0.1995711 -0.2426290 -0.2620812 -0.3588752
#>
#> , , 5
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.4701264 1.03459813 -0.07049092 -0.9481237 -0.394103521 0.54108291
#> [2,] 0.4693224 -0.84483972 1.80414176 -1.5155320 -1.510240230 -0.54004111
#> [3,] -1.4753401 -1.01694912 0.44463712 0.2665382 0.005989837 -0.08084940
#> [4,] -0.9159547 0.67475583 -1.19094010 0.2915323 0.855006991 -0.02963396
#> [5,] 0.4579751 -0.03322678 0.24822910 1.7089224 0.729851453 -0.14525048
#> [6,] -0.7125025 2.24549141 -0.11897816 0.4767018 0.348758873 -0.01086260
#> [7,] -0.3784383 -0.45414694 0.68698898 1.3075518 1.361367470 -1.37871876
#> [8,] 2.0068609 0.19487458 -1.40777779 1.8060127 -0.288662129 0.67153568
#> [9,] -0.5501684 0.03149807 0.57532204 1.0353860 1.888403664 -1.15420545
#> [10,] -1.9807862 -1.78933099 0.63770153 0.5165183 -0.017375770 0.42259779
#> [,7] [,8] [,9] [,10]
#> [1,] -0.3869897 1.36036594 0.07671589 -0.82923568
#> [2,] -1.2405260 -0.26652359 -0.26087926 -0.44575212
#> [3,] 0.4569621 -3.03494577 -0.92187041 -0.67091205
#> [4,] -1.4107934 -0.23881991 0.11760616 -0.80091690
#> [5,] 1.9339075 -0.27218672 -2.13841022 1.61094670
#> [6,] 0.5695607 1.19039680 -0.31941960 0.01851833
#> [7,] 0.9327798 0.05119609 -0.74069441 -1.08339934
#> [8,] -1.5453473 0.33104803 -0.92579143 1.28944976
#> [9,] 0.6016184 0.53161910 0.75793379 -0.14391274
#> [10,] -0.9507662 0.61403147 0.35956026 -2.28800884
#>
#> , , 6
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.084716818 0.8215494 -0.50981520 1.88523498 -0.9375378 -1.69827370
#> [2,] 0.199059827 -1.3357694 -0.75877632 0.84319900 0.4204740 0.09469637
#> [3,] 1.229825830 1.0431180 3.40187203 0.33453392 -0.5392022 0.76213934
#> [4,] 0.004552531 -1.1229909 -0.45041599 0.02038547 0.8685939 2.36720359
#> [5,] -1.294607637 0.6909233 1.72919815 -1.00729154 1.1501575 -0.04370282
#> [6,] -0.397161380 0.3686056 -0.71848829 0.41269396 0.0176960 0.06709804
#> [7,] 1.739481988 0.6485134 0.53361960 -0.76703234 -0.9278443 0.15529692
#> [8,] 1.023020955 -0.4398303 -0.07018693 0.92499188 -0.5057319 -0.53287289
#> [9,] -0.527567252 -0.8664209 -1.55056351 0.30914945 1.2257332 -1.82897354
#> [10,] 0.845996179 0.8653006 0.27342752 1.96684536 1.2103777 0.60055463
#> [,7] [,8] [,9] [,10]
#> [1,] 0.08534008 0.4672982 -0.79850201 -0.33097479
#> [2,] -0.39657356 0.5538269 -1.01728786 1.49159813
#> [3,] -1.61741431 -0.6809784 1.01498892 0.17209021
#> [4,] -0.02290525 -2.7949596 -0.65150769 0.19116028
#> [5,] 0.40628102 -1.0845861 0.03821585 -0.27961501
#> [6,] 0.50904587 -0.6570978 0.18407867 0.77501956
#> [7,] 1.58667108 -0.9692907 0.45172259 -0.33584529
#> [8,] 1.04631178 0.4127632 0.30788006 -0.01052949
#> [9,] -1.04793831 -0.9154103 0.28485823 -0.13913500
#> [10,] -0.79060053 -0.4483160 0.66455104 -0.05346595
#>
#> , , 7
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1.3294962 -1.00383169 -0.8735572 -0.22922105 -1.5295554 -0.6110400
#> [2,] 0.9897694 1.78420320 0.1119540 -0.26781309 1.7241555 -0.4634798
#> [3,] 1.6645658 -0.86714456 1.5142314 0.37369104 0.2045693 -1.4817114
#> [4,] -2.1198836 -0.97057478 0.3765598 0.98053555 1.2378090 -0.3041410
#> [5,] 0.1414808 -1.20287478 1.2972814 2.28129142 0.2429637 0.3132652
#> [6,] -0.1778062 -0.36731350 2.5623566 0.53232497 1.0135437 -0.2650185
#> [7,] 0.2978839 0.01377361 -1.0020247 0.49883079 1.2824897 -1.3603385
#> [8,] 1.1394333 1.32008871 0.8006673 0.15410050 0.2892092 0.3944052
#> [9,] 0.1267375 0.48927367 -1.0359882 0.08277325 -2.4036860 0.5387158
#> [10,] -0.4859503 -1.20238027 1.3658775 -1.58597729 2.2685937 2.1372920
#> [,7] [,8] [,9] [,10]
#> [1,] 0.20729822 0.8732661 -0.62801764 0.4104312
#> [2,] -1.27663928 0.6897053 0.25333362 0.5518676
#> [3,] -0.51566945 -0.8533945 -0.02518879 -2.1221467
#> [4,] -0.07889564 0.6541665 -0.18662069 -0.1138994
#> [5,] 0.63834847 1.4000088 -0.23337973 -0.2736715
#> [6,] 0.81292503 1.0024323 2.72420705 0.2083771
#> [7,] -0.89318478 -3.0421103 -2.79259301 2.3648680
#> [8,] -0.40159558 -0.2422741 1.65141713 1.6055654
#> [9,] 0.82412795 1.8518099 2.60954671 1.6538888
#> [10,] -1.30401071 -1.6767816 -0.60324688 2.2142716
#>
#> , , 8
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.44111991 0.4342333 -0.89447137 0.5136547 0.2445857 0.024357435
#> [2,] 0.56334117 0.2961612 -0.01776011 0.3397094 -0.7053527 -0.937410840
#> [3,] 1.18008944 -0.9716477 0.42230297 -0.2641079 -1.5612190 0.009875067
#> [4,] -0.93377333 -0.6409022 0.12337071 0.4451025 -0.7577141 -1.218941756
#> [5,] -0.02200709 0.9229221 -1.65847723 1.3680193 1.5420985 0.690627111
#> [6,] -0.23324656 -1.0862926 -0.12786525 -0.8215120 -0.0646699 0.461008072
#> [7,] -1.22414612 0.4600906 -0.89058031 0.1913186 -0.9665788 0.565864491
#> [8,] 0.56431414 -0.2181480 0.89698542 1.4468181 0.3758670 -0.042363881
#> [9,] 0.71812162 1.3230111 1.35092937 -1.0034288 -2.0208102 0.494492116
#> [10,] -0.77199334 0.2853028 -1.03205295 0.6153732 0.2447926 -0.773181892
#> [,7] [,8] [,9] [,10]
#> [1,] 1.5808633 -1.96328141 0.98731340 0.4150048
#> [2,] -1.8251636 0.30316908 -1.51643919 0.3540266
#> [3,] 0.3268752 0.61376372 -0.01835978 -0.7646000
#> [4,] -0.2806893 0.74867756 -0.58937828 -0.5090992
#> [5,] 0.8980972 -0.02573749 0.20625589 -1.7974375
#> [6,] -0.6415268 0.71694826 0.45214256 -0.2999656
#> [7,] 0.1412008 1.07911836 0.66605262 -0.4502200
#> [8,] -1.6545119 -0.12360282 -0.52697709 0.9263556
#> [9,] -1.9847285 0.72963842 0.02512841 -1.4013414
#> [10,] -0.5143259 0.20994556 0.55199547 1.2660778
#>
#> , , 9
#>
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] -0.23756597 0.04836372 1.2651925 0.71004247 -0.06357811 0.1551941
#> [2,] -0.91430359 -1.29630589 1.1552432 2.07437921 -0.73226820 1.2495368
#> [3,] 1.44336433 -1.07200011 1.6734299 -0.08267674 1.50005860 0.4968856
#> [4,] -0.01370158 -0.02053225 0.6296572 -1.19144102 -0.30283086 -0.3090768
#> [5,] -0.53039735 -0.70849079 -1.1744451 -2.60479611 0.85362520 -0.5492284
#> [6,] 0.80979975 1.02394779 0.7989220 0.41789122 -0.40174876 0.3575519
#> [7,] -0.33522667 1.08235408 1.2099618 0.13196928 -0.71358591 1.0833902
#> [8,] -1.43914535 0.55476813 -0.5448537 0.49800750 -2.13141016 0.8411405
#> [9,] 1.86129327 1.58677996 1.1828370 0.21705236 0.54529463 -0.2644799
#> [10,] 0.05318576 0.25886095 -0.5561691 0.05370814 0.21744146 -0.8447493
#> [,7] [,8] [,9] [,10]
#> [1,] -0.423713730 -1.19361593 0.2450356 -0.5730251
#> [2,] 0.267596434 0.51296587 -0.2109977 -0.8768324
#> [3,] 0.313787615 0.04013688 0.3065782 1.1075260
#> [4,] 0.968423223 0.69473425 0.2167695 -0.9133941
#> [5,] -0.520841792 0.84025170 -0.6667214 1.2256126
#> [6,] -0.005744297 -0.65504037 -0.9637464 -1.1532241
#> [7,] 0.952890749 0.76272563 -1.2925099 -0.8020893
#> [8,] 0.715788002 1.19746787 0.6900559 -1.3012467
#> [9,] -0.521479412 -2.17800743 2.1973152 -0.5441865
#> [10,] -0.347252939 -0.14910974 -0.0992651 0.8624957
#>
#> , , 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
#>