pip install imgvision
Xuheng Cao (caoxuhengcn@gmail.com)
This Class is to create a standard CIE illuminance for the subsequent operation.
In[1]: import numpy as np
import imgvision as iv
Illuminate_D65 = iv.spectra('d65')
Illuminate_A = iv.spectra('a')
Illuminate_D75 = iv.spectra('d75')
Illuminate_D50 = iv.spectra('d50')
The following example shows a mapping between a hyperspectral image with 31 bands from 400nm~700nm and the corresponding sRGB image.
In[2]: import matplotlib.pyplot as plt
sample_SI = np.random.rand(100,100,31)
sample_MI = Illuminate_D65.space(sample_SI,'srgb')
plt.imshow(sample_MI)
plt.show()
The downsample function aims at downsampling with any scale factor for an image.
In[3]: LR_sample_SI = iv.downsample(sample_SI,5)
print(LR_sample_SI.shape)
Out: (20, 20, 31)
This function is to convert an RGB image (no matter how is it depth) to the HSV color space. hsv2rgb excutes the contrary operation.
In[4]: sample_HSV = iv.color.rgb2hsv(sample_MI)
In[5]: sample_RGB = iv.color.hsv2rgb(sample_HSV)
Calculate the Cosine Similarity distance between two color images and return a 1-D vector, the vector include the Cosine Similarity distance of each element. This function supports the shape of input as a 2-D matrix (an RGB vector) and a 3-D tensor (a color image).
In[6]: a= np.random.rand(128,128,3)
b= np.random.rand(128,128,3)
dist = iv.distance.cosine(a,b)
print(f'Shape: {dist.shape}\nMean distance: {dist.mean()}')
Out: Shape: (16384,)
Mean distance: 0.2055142334948004
Predict clusters each pixel of a given image belongs to according to Cosine Similarity distance and given cluster center.
In[7]: img = np.random.rand(128,128,3)
centre = np.array([ [0.3,0.5,0.1],
[0.8,0.1,0.3] ])
cluster_id = cluster.cosine_predict(img,centre)
print(cluster_id)
Out: [1 1 1 ... 1 0 1]
The following example shows a quantitative evaluation between a hyperspectral image with 31 bands from 400nm to 700nm and the corresponding reconstructed image.
In[8]: sample_GT = np.random.rand(100,100,31)
sample_SI = np.random.rand(100,100,31)
Metric = iv.spectra_metric(sample_GT,sample_SI, scale=32)
PSNR = Metric.PSNR()
SSIM = Metric.SSIM()
MSE = Metric.MSE()
SAM = Metric.SAM()
ERGAS = Metric.ERGAS()
CC = Metric.CC()
print(PSNR,SSIM,MSE,SAM,EGRAS)
Out: [7.765805543824359 0.0041294934819296365 0.16728452073841815 41.049350569568816 5.116354915189658]