Keywords: Graphics, Image Processing, Color Science, RGB, Grayscale

### Documents

##### Texture Formats

Texture formats
http://wiki.polycount.com/wiki/Texture_formats

##### Grayscale

Converting RGB to grayscale/intensity
https://stackoverflow.com/questions/687261/converting-rgb-to-grayscale-intensity

https://blog.csdn.net/zaishuiyifangxym/article/details/89817995

##### Interpolation

Bicubic interpolation
https://en.wikipedia.org/wiki/Bicubic_interpolation

Cubic Hermite spline
https://en.wikipedia.org/wiki/Cubic_Hermite_spline

### Applications

##### Grayscale

Q: How to compute grayscale in UE4 Materials?
A: The dot product of a RGB color and a coefficient is grayscale, this value can be used to computing falloff.

and you can get a new color with grayscale modified by appending these individual channels.

### Ordinary Tricks on OpenCV-Python

##### How do I access the pixels of an image using OpenCV-Python?
``````import cv2
pixel= image[200, 550]
print pixel
``````

output:

``````[ 73 89 102]
``````

pixel_b, pixel_g, pixel_r = image[row][column]

##### Add an alpha channel to a image

Python opencv adds an alpha channel to the image and sets the transparency:

``````import cv2
import numpy as np

b_channel, g_channel, r_channel = cv2.split(img)

alpha_channel = np.ones(b_channel.shape, dtype=b_channel.dtype) * 255
#minimum is 0
alpha_channel[:, :int(b_channel.shape / 2)] = 100

img_BGRA = cv2.merge((b_channel, g_channel, r_channel, alpha_channel))

cv2.imwrite("lena.png", img_BGRA)
``````

Python with OpenCV3

``````# First create the image with alpha channel
rgba = cv2.cvtColor(rgb_data, cv2.COLOR_RGB2RGBA)

# Then assign the mask to the last channel of the image
rgba[:, :, 3] = alpha_data
``````

C++

``````# First create the image with alpha channel
cv::cvtColor(rgb_data, rgba , cv::COLOR_RGB2RGBA);

std::vector<cv::Mat>channels(4);
cv::split(rgba, channels);

# Assign the mask to the last channel of the image
channels = alpha_data;

# Finally concat channels for rgba image
cv::merge(channels, 4, rgba);
``````
##### Get alpha channel of a image
``````dir_of_script =  pathlib.Path(__file__).parent.absolute()
full_path = os.path.join(dir_of_script, "heightmap.png")
#(400, 250) is just pixel postion for testing
pixel = image[400, 250]
# would print 4 channels
print(pixel)
``````

Output:

``````[  0   0   0 118]
``````
##### Create transparent image in opencv python
``````import numpy as np
import cv2

img_height, img_width = 300, 300
n_channels = 4
transparent_img = np.zeros((img_height, img_width, n_channels), dtype=np.uint8)

# Save the image for visualization
cv2.imwrite("./transparent_img.png", transparent_img)
``````

`Then he made one last effort to search in his heart for the place where his affection had rotted away, and he could not find it. ― Gabriel Garcia Marquez, One Hundred Years of Solitude`