Calculates the range of values in an image, then scales the image minimum to 0 and maximum to 1
minmax_img(img)
# S4 method for nifti
minmax_img(img)
# S4 method for array
minmax_img(img)
# S4 method for ANY
minmax_img(img)
# S4 method for character
minmax_img(img)
# S4 method for factor
minmax_img(img)
# S4 method for list
minmax_img(img)
img | character path of image or
an object of class |
---|
A nifti
object (or list of them) or class of
object passed in if not specified
set.seed(5)
dims = rep(10, 4)
arr = array(rpois(prod(dims), lambda = 2), dim = dims)
nim = oro.nifti::nifti(arr)
mimg = minmax_img(nim)
marr = minmax_img(arr)
testthat::expect_equal(array(mimg, dim = dim(mimg)), marr)
set.seed(5)
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), factor(timg))
func = minmax_img
func(arr)
#> , , 1
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.3851058 0.6848894 0.6374804 0.5527554 0.7316188 0.7190373 0.3422463
#> [2,] 0.7076039 0.3907691 0.6434743 0.6677970 0.3906758 0.5341771 0.6308598
#> [3,] 0.3250130 0.3503899 0.7197204 0.8280546 0.4961615 0.6550909 0.4231475
#> [4,] 0.5171359 0.4841388 0.6094003 0.6833637 0.7817074 0.4211961 0.5789073
#> [5,] 0.7550075 0.3516410 0.6256683 0.7213523 0.4408001 0.4907090 0.3968157
#> [6,] 0.4195913 0.4868270 0.4644361 0.6448808 0.5884526 0.3729176 0.4574934
#> [7,] 0.4385395 0.4204022 0.7125648 0.3606596 0.3784169 0.6161458 0.2022817
#> [8,] 0.4148864 0.1904501 0.7241859 0.2170437 0.4402674 0.4906498 0.4632447
#> [9,] 0.4655533 0.5418715 0.4117399 0.2515783 0.4019939 0.4976815 0.3225649
#> [10,] 0.5269860 0.4693820 0.3833754 0.4863021 0.4969394 0.5407785 0.4664384
#> [,8] [,9] [,10]
#> [1,] 0.4773905 0.5792051 0.6411812
#> [2,] 0.4742721 0.2544600 0.3529960
#> [3,] 0.5572646 0.6483526 0.5877005
#> [4,] 0.5116612 0.5034798 0.6375121
#> [5,] 0.5669028 0.6048964 0.6504420
#> [6,] 0.4844556 0.4040257 0.5625661
#> [7,] 0.6480564 0.8529493 0.4567401
#> [8,] 0.5245196 0.4383561 0.4286811
#> [9,] 0.5343869 0.4959885 0.4805125
#> [10,] 0.4253918 0.4313404 0.4983759
#>
#> , , 2
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.2177807 0.3688666 0.6766612 0.7024140 0.3916074 0.6440858 0.1270613
#> [2,] 0.6715097 0.7420999 0.6352098 0.2202240 0.5027160 0.6159235 0.8325175
#> [3,] 0.6049124 0.8838061 0.3159699 0.3271204 0.8229495 0.4319872 0.5205111
#> [4,] 0.5371854 0.5272093 0.2688154 0.4918919 0.6457278 0.6241215 0.7428102
#> [5,] 0.4985866 0.3112117 0.6604862 0.6131992 0.4627597 0.4179062 0.4329234
#> [6,] 0.6365093 0.6227584 0.5490117 0.5730113 0.4463314 0.6864297 0.4114067
#> [7,] 0.4738009 0.2816062 0.4489937 0.5487212 0.5214564 0.4579704 0.5011454
#> [8,] 0.2220901 0.5741766 0.6871307 0.3513612 0.4736641 0.6803583 0.4897679
#> [9,] 0.3977646 0.5145687 0.3089376 0.6009917 0.3018645 0.4427205 0.5041213
#> [10,] 0.6925012 0.4776899 0.2980676 0.5503274 0.4500712 0.5339436 0.4365812
#> [,8] [,9] [,10]
#> [1,] 0.2982510 0.8231540 0.6037158
#> [2,] 0.5278064 0.4078716 0.5600485
#> [3,] 0.3280427 0.6156755 0.4323400
#> [4,] 0.2529819 0.6481864 0.5722705
#> [5,] 0.5018257 0.3237113 0.4797640
#> [6,] 0.5550916 0.4667637 0.7010401
#> [7,] 0.7348403 0.4795208 0.6252640
#> [8,] 0.3519729 0.4513138 0.5188836
#> [9,] 0.6397666 0.6143028 0.4126413
#> [10,] 0.4207384 0.3376440 0.6122479
#>
#> , , 3
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.4904949 0.6835709 0.5375259 0.4516097 0.5510847 0.4695485 0.2960032
#> [2,] 0.4642015 0.5981500 0.5021441 0.6486655 0.4899412 0.4682887 0.5205623
#> [3,] 0.6503293 0.5834559 0.8004799 0.4260938 0.4982620 0.5307611 0.6493410
#> [4,] 0.3946311 0.4385267 0.4532324 0.4161786 0.7201518 0.4499465 0.4204895
#> [5,] 0.5469558 0.6263503 0.2782382 0.4300924 0.2927437 0.2397592 0.5178115
#> [6,] 0.5665043 0.4449712 0.4893508 0.7819905 0.4078948 0.2834479 0.8254414
#> [7,] 0.5955483 0.4862969 0.2465796 0.7092244 0.5737158 0.4220069 0.6221920
#> [8,] 0.6427064 0.7125929 0.4380431 0.3988494 0.4806652 0.3834705 0.4288618
#> [9,] 0.4537027 0.5775700 0.3788381 0.4626837 0.3390241 0.6197719 0.2748978
#> [10,] 0.6142722 0.5944263 0.0000000 0.6764904 0.5662488 0.5025763 0.4009729
#> [,8] [,9] [,10]
#> [1,] 0.4554130 0.5251086 0.4752707
#> [2,] 0.3641550 0.3950220 0.6058976
#> [3,] 0.4010023 0.3601620 0.5829318
#> [4,] 0.7193381 0.6471048 0.5186442
#> [5,] 0.7763374 0.4456177 0.5147652
#> [6,] 0.5074770 0.3864473 0.4001199
#> [7,] 0.3122182 0.7098645 0.6470350
#> [8,] 0.5288970 0.5094360 0.6496247
#> [9,] 0.5490009 0.7747260 0.5341140
#> [10,] 0.4892195 0.4074997 0.5465337
#>
#> , , 4
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.6823554 0.3822260 0.4542747 0.3438386 0.08885856 0.2010895 0.3857694
#> [2,] 0.5343120 0.6864842 0.7061973 0.4751786 0.16860563 0.5447497 0.8011176
#> [3,] 0.7913931 0.6181938 0.5492743 0.4875050 0.25611386 0.6440102 0.5691600
#> [4,] 0.5270735 0.3493730 0.6099555 0.3884152 0.62653794 0.4171199 0.6611670
#> [5,] 0.2781813 0.5167534 0.3710614 0.5754250 0.35551362 0.5056512 0.4191688
#> [6,] 0.3914587 0.7396015 0.3455101 0.3809897 0.37983939 0.5823659 0.6626779
#> [7,] 0.6844145 0.6855559 0.5989090 0.3138829 0.44894205 0.7687494 0.4037303
#> [8,] 0.4540227 0.4520256 0.4734636 0.5171967 0.32317280 0.2297906 0.4810481
#> [9,] 0.4834061 0.3113353 0.3086791 0.5742307 0.52705532 0.5358519 0.5793999
#> [10,] 0.5881998 0.5598573 0.3975622 0.5488776 0.67850397 0.5470408 0.4780465
#> [,8] [,9] [,10]
#> [1,] 0.5199985 0.8136467 0.4478511
#> [2,] 0.6526107 0.6792385 0.5361459
#> [3,] 0.2355266 0.6367194 0.4008897
#> [4,] 0.5830266 0.6328469 0.6126430
#> [5,] 0.4323857 0.7469983 0.5543110
#> [6,] 0.6824694 0.7164847 0.1145201
#> [7,] 0.4326512 0.6148843 0.4211520
#> [8,] 0.6650334 0.4069416 0.5800931
#> [9,] 0.5782527 0.3922716 0.2862872
#> [10,] 0.4718062 0.4689870 0.4549587
#>
#> , , 5
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.4388352 0.6569134 0.4967540 0.3695595 0.4498531 0.5853887 0.4508841
#> [2,] 0.5749886 0.3845284 0.7684426 0.2873256 0.2880926 0.4287025 0.3271820
#> [3,] 0.2931506 0.3595847 0.5714109 0.5455992 0.5078382 0.4952527 0.5731972
#> [4,] 0.3742218 0.6047618 0.3343684 0.5492216 0.6308854 0.5026753 0.3025053
#> [5,] 0.5733440 0.5021546 0.5429457 0.7546425 0.6127468 0.4859191 0.7872494
#> [6,] 0.4037079 0.8324069 0.4897268 0.5760581 0.5575154 0.5053958 0.5895160
#> [7,] 0.4521235 0.4411511 0.6065348 0.6964723 0.7042717 0.3071538 0.6421570
#> [8,] 0.7978225 0.5352131 0.3029423 0.7687137 0.4651346 0.6042951 0.2830045
#> [9,] 0.4272348 0.5115351 0.5903510 0.6570276 0.7806546 0.3396923 0.5941621
#> [10,] 0.2198968 0.2476442 0.5993916 0.5818286 0.5044519 0.5682168 0.3691766
#> [,8] [,9] [,10]
#> [1,] 0.70412659 0.5180885 0.3867899
#> [2,] 0.46834315 0.4691612 0.4423677
#> [3,] 0.06711853 0.3733644 0.4097355
#> [4,] 0.47235821 0.5240147 0.3908941
#> [5,] 0.46752239 0.1970525 0.7404430
#> [6,] 0.67949314 0.4606770 0.5096540
#> [7,] 0.51438994 0.3996220 0.3499542
#> [8,] 0.55494859 0.3727961 0.6938488
#> [9,] 0.58401715 0.6168167 0.4861130
#> [10,] 0.59596110 0.5590808 0.1753713
#>
#> , , 6
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.4946922 0.6260365 0.4330831 0.7801953 0.3710937 0.2608411 0.5193384
#> [2,] 0.5358197 0.3133784 0.3970015 0.6291741 0.5679090 0.5206944 0.4494951
#> [3,] 0.6852075 0.6581482 1.0000000 0.5554538 0.4288241 0.6174262 0.2725599
#> [4,] 0.5076299 0.3442162 0.4416918 0.5099246 0.6328546 0.8500466 0.5036505
#> [5,] 0.3193440 0.6071050 0.7575811 0.3609844 0.6736613 0.5006363 0.5658520
#> [6,] 0.4494099 0.5603918 0.4028404 0.5667815 0.5095348 0.5166946 0.5807456
#> [7,] 0.7590715 0.6009585 0.5843071 0.3958049 0.3724986 0.5294772 0.7369248
#> [8,] 0.6552355 0.4432260 0.4967980 0.6410283 0.4336749 0.4297414 0.6586110
#> [9,] 0.4305104 0.3814006 0.2822485 0.5517749 0.6846144 0.2418989 0.3550935
#> [10,] 0.6295795 0.6323773 0.5465977 0.7920230 0.6823890 0.5940079 0.3923892
#> [,8] [,9] [,10]
#> [1,] 0.5746952 0.3912441 0.4590023
#> [2,] 0.5872357 0.3595356 0.7231459
#> [3,] 0.4082766 0.6540715 0.5319110
#> [4,] 0.1018995 0.4125478 0.5346748
#> [5,] 0.3497822 0.5125087 0.4664458
#> [6,] 0.4117376 0.5336485 0.6192929
#> [7,] 0.3664918 0.5724378 0.4582964
#> [8,] 0.5667915 0.5515909 0.5054441
#> [9,] 0.3743007 0.5482544 0.4868054
#> [10,] 0.4419962 0.6032828 0.4992214
#>
#> , , 7
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.6996527 0.3614858 0.3803664 0.4737494 0.2852932 0.4184127 0.5370137
#> [2,] 0.6504164 0.7655529 0.5231955 0.4681563 0.7568502 0.4397985 0.3219481
#> [3,] 0.7482140 0.3812958 0.7264262 0.5611288 0.5366182 0.2922272 0.4322347
#> [4,] 0.1997376 0.3663057 0.5615446 0.6490782 0.6863645 0.4628913 0.4955359
#> [5,] 0.5274748 0.3326387 0.6949838 0.8375954 0.5421826 0.5523713 0.5994853
#> [6,] 0.4812009 0.4537358 0.8783299 0.5841195 0.6538620 0.4685613 0.6247865
#> [7,] 0.5501422 0.5089663 0.3617477 0.5792652 0.6928401 0.3098177 0.3775218
#> [8,] 0.6721071 0.6982893 0.6230100 0.5293038 0.5488849 0.5641309 0.4487673
#> [9,] 0.5253381 0.5778801 0.3568254 0.5189664 0.1586064 0.5850457 0.6264102
#> [10,] 0.4365419 0.3327104 0.7049254 0.2771161 0.8357551 0.8167257 0.3179812
#> [,8] [,9] [,10]
#> [1,] 0.63353171 0.4159522 0.5664535
#> [2,] 0.60692842 0.5436855 0.5869517
#> [3,] 0.38328854 0.5033196 0.1994096
#> [4,] 0.60177782 0.4799234 0.4904628
#> [5,] 0.70987199 0.4731467 0.4673072
#> [6,] 0.65225163 0.9017867 0.5371700
#> [7,] 0.06608018 0.1022425 0.8497081
#> [8,] 0.47185760 0.7463083 0.7396631
#> [9,] 0.77535107 0.8851691 0.7466666
#> [10,] 0.26395588 0.4195422 0.8278823
#>
#> , , 8
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.4430391 0.5699031 0.3773353 0.5814136 0.5424177 0.5105002 0.7360830
#> [2,] 0.5886146 0.5498925 0.5043962 0.5562039 0.4047441 0.3711121 0.2424510
#> [3,] 0.6779993 0.3661502 0.5681741 0.4686933 0.2807042 0.5084013 0.5543438
#> [4,] 0.3716393 0.4140848 0.5248501 0.5714784 0.3971554 0.3303101 0.4662901
#> [5,] 0.5037807 0.6407283 0.2666087 0.7052358 0.7304649 0.6070620 0.6371305
#> [6,] 0.4731660 0.3495349 0.4884388 0.3879092 0.4975976 0.5737836 0.4139943
#> [7,] 0.3295559 0.5736506 0.3778992 0.5346978 0.3668848 0.5889803 0.5274342
#> [8,] 0.5887556 0.4753542 0.6369693 0.7166560 0.5614442 0.5008304 0.2671834
#> [9,] 0.6110468 0.6987128 0.7027590 0.3615442 0.2140962 0.5786364 0.2193255
#> [10,] 0.3950859 0.5483188 0.3573958 0.5961556 0.5424477 0.3949137 0.4324294
#> [,8] [,9] [,10]
#> [1,] 0.2224338 0.6500605 0.5671164
#> [2,] 0.5509081 0.2871941 0.5582789
#> [3,] 0.5959223 0.5043093 0.3961574
#> [4,] 0.6154752 0.4215521 0.4331869
#> [5,] 0.5032400 0.5368626 0.2464693
#> [6,] 0.6108767 0.5724987 0.4634964
#> [7,] 0.6633657 0.6035005 0.4417202
#> [8,] 0.4890565 0.4305959 0.6412259
#> [9,] 0.6127159 0.5106120 0.3038751
#> [10,] 0.5373973 0.5869703 0.6904615
#>
#> , , 9
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.4725399 0.5139794 0.6903332 0.6098759 0.4977558 0.5294623 0.4455617
#> [2,] 0.3744610 0.3190978 0.6743984 0.8076078 0.4008433 0.6880642 0.5457526
#> [3,] 0.7161555 0.3516063 0.7494986 0.4949879 0.7243721 0.5789833 0.5524471
#> [4,] 0.5049844 0.5039944 0.5982257 0.3342958 0.4630812 0.4621760 0.6473227
#> [5,] 0.4301002 0.4042893 0.3367590 0.1294597 0.6306852 0.4273710 0.4314851
#> [6,] 0.6243336 0.6553699 0.6227571 0.5675347 0.4487451 0.5587898 0.5061376
#> [7,] 0.4583861 0.6638346 0.6823287 0.5260963 0.4035509 0.6639848 0.6450716
#> [8,] 0.2983963 0.5873721 0.4280050 0.5791459 0.1980670 0.6288758 0.6107086
#> [9,] 0.7767255 0.7369405 0.6783975 0.5384273 0.5859991 0.4686393 0.4313927
#> [10,] 0.5146783 0.5444866 0.4263651 0.5147540 0.5384837 0.3845415 0.4566431
#> [,8] [,9] [,10]
#> [1,] 0.3339806 0.5424829 0.4239222
#> [2,] 0.5813138 0.4763905 0.3798917
#> [3,] 0.5127871 0.5514022 0.6674828
#> [4,] 0.6076573 0.5383863 0.3745929
#> [5,] 0.6287470 0.4103429 0.6845969
#> [6,] 0.4120358 0.3672954 0.3398345
#> [7,] 0.6175112 0.3196480 0.3907242
#> [8,] 0.6805179 0.6069792 0.3183818
#> [9,] 0.1913137 0.8254248 0.4281017
#> [10,] 0.4853598 0.4925837 0.6319708
#>
#> , , 10
#>
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [2,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [3,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [4,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [5,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [6,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [7,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [8,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [9,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [10,] 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701 0.5069701
#> [,8] [,9] [,10]
#> [1,] 0.5069701 0.5069701 0.5069701
#> [2,] 0.5069701 0.5069701 0.5069701
#> [3,] 0.5069701 0.5069701 0.5069701
#> [4,] 0.5069701 0.5069701 0.5069701
#> [5,] 0.5069701 0.5069701 0.5069701
#> [6,] 0.5069701 0.5069701 0.5069701
#> [7,] 0.5069701 0.5069701 0.5069701
#> [8,] 0.5069701 0.5069701 0.5069701
#> [9,] 0.5069701 0.5069701 0.5069701
#> [10,] 0.5069701 0.5069701 0.5069701
#>
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)
#> Image array of mode "double" (9.1 Kb)
#> - 10 x 10 x 10 voxels
#> - 1 x 1 x 1 per voxel
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
#>