source
chans
chans (x:numpy.ndarray, cmap:str='twilight', cm_below:str='blue',
cm_above:str='red', cm_ninf:str='cyan', cm_pinf:str='fuchsia',
cm_nan:str='yellow', gutter_px:int=3, frame_px:int=1, scale:int=1,
cl:Any=True, view_width:int=966,
ax:Optional[matplotlib.axes._axes.Axes]=None)
Map x values to colors. RGB[A] color is added as channel-last
x |
ndarray |
|
Input array |
cmap |
str |
twilight |
Use matplotlib colormap by this name |
cm_below |
str |
blue |
|
cm_above |
str |
red |
|
cm_ninf |
str |
cyan |
|
cm_pinf |
str |
fuchsia |
|
cm_nan |
str |
yellow |
|
gutter_px |
int |
3 |
Draw write gutters when tiling the images |
frame_px |
int |
1 |
Draw black frame around each image |
scale |
int |
1 |
Stretch the image. Only itegers please. |
cl |
Any |
True |
|
view_width |
int |
966 |
|
ax |
Optional |
None |
|
Returns |
ChanProxy |
|
|
in_stats = ( (0.485, 0.456, 0.406), (0.229, 0.224, 0.225) )
image = np.load("mysteryman.npy").transpose(1,2,0)
image = ((image * np.array(in_stats[1])) + np.array(in_stats[0])).clip(0, 1)
print(lo(image))
rgb(image)
array[196, 196, 3] n=115248 (0.9Mb) xโ[0., 1.000] ฮผ=0.361 ฯ=0.248
display(chans(image)) # 3d array is tiled
display(chans(image[:,:,0])) # Works with 2d arrays too
# In R
image[0:32, 32:64, 0] = -1.1 # Below min
image[0:32, 96:128, 0] = 1.1 # Above max
# In G
image[0:32, 64:96, 1] = float("nan")
# In B
image[0:32, 0:32, 2] = float("-inf")
image[0:32, 128:160,2] = float("+inf")
image[0:32, 160:176,1] = 0.
image[0:32, 176: ,1] = 1.
chans(image, cmap="bwr", cm_below="black", cm_above="white")
array[4, 196, 196, 3] n=460992 (3.5Mb) xโ[-1.100, 1.100] ฮผ=0.360 ฯ=0.298 +Inf! -Inf! NaN!
# 4 images, stacked 2x2
chans(np.stack([image]*4).reshape((2,2,196,196,3)))
one_chan = image[:,:,0] # 1-channel image
chans(one_chan)
try:
chans(np.array([]).reshape(0,0,0))
except AssertionError as e:
test_eq(e.args[0], "Expecting non-empty input, got shape=((0, 0, 0, 3))")
else:
raise AssertionError("Expected AssertionError, but got nothing")