[5d12a0]: / ants / utils / scalar_rgb_vector.py

Download this file

93 lines (76 with data), 2.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
__all__ = ['rgb_to_vector',
'vector_to_rgb',
'scalar_to_rgb']
import os
from tempfile import mktemp
import numpy as np
import ants
from ants.internal import get_lib_fn, process_arguments
from ants.decorators import image_method
def scalar_to_rgb(image, mask=None, filename=None, cmap='red', custom_colormap_file=None,
min_input=None, max_input=None, min_rgb_output=None, max_rgb_output=None,
vtk_lookup_table=None):
"""
Usage: ConvertScalarImageToRGB imageDimension inputImage outputImage mask colormap
[customColormapFile] [minimumInput] [maximumInput] [minimumRGBOutput=0]
[maximumRGBOutput=255] <vtkLookupTable>
Possible colormaps: grey, red, green, blue, copper, jet, hsv, spring, summer, autumn, winter, hot, cool, overunder, custom
Example
-------
>>> import ants
>>> img = ants.image_read(ants.get_data('r16'))
>>> img_color = ants.scalar_to_rgb(img, cmap='jet')
"""
raise Exception('This function is currently not supported.')
@image_method
def rgb_to_vector(image):
"""
Convert an RGB ANTsImage to a Vector ANTsImage
Arguments
---------
image : ANTsImage
RGB image to be converted
Returns
-------
ANTsImage
Example
-------
>>> import ants
>>> mni = ants.image_read(ants.get_data('mni'))
>>> mni_rgb = ants.scalar_to_rgb(mni)
>>> mni_vector = mni.rgb_to_vector()
>>> mni_rgb2 = mni.vector_to_rgb()
"""
if image.pixeltype != 'unsigned char':
image = image.clone('unsigned char')
idim = image.dimension
libfn = get_lib_fn('RgbToVector%i' % idim)
new_ptr = libfn(image.pointer)
new_img = ants.from_pointer(new_ptr)
return new_img
@image_method
def vector_to_rgb(image):
"""
Convert an Vector ANTsImage to a RGB ANTsImage
Arguments
---------
image : ANTsImage
RGB image to be converted
Returns
-------
ANTsImage
Example
-------
>>> import ants
>>> img = ants.image_read(ants.get_data('r16'), pixeltype='unsigned char')
>>> img_rgb = ants.scalar_to_rgb(img.clone())
>>> img_vec = img_rgb.rgb_to_vector()
>>> img_rgb2 = img_vec.vector_to_rgb()
"""
if image.pixeltype != 'unsigned char':
image = image.clone('unsigned char')
idim = image.dimension
libfn = get_lib_fn('VectorToRgb%i' % idim)
new_ptr = libfn(image.pointer)
new_img = ants.from_pointer(new_ptr)
return new_img