<jupyter_start><jupyter_text>Intensity Transformation(Point operations)In intensity transformations the output value of a given pixel depends only on that pixel. That is the output pixel's value is a function of the pixel itself. 1. Identity Transformation* Transformation does not change the image.* 0 maps to 0* 255 maps to 255 `img2 = cv.LUT(img, transform)`This is basically a Look Up Table(LUT) operation.|Pixels Value|LUT||:---:|:---:||0|0||1|1||2|2||:|:||:|:||255|255|Each pixel has a corresponding value associated with it. By using the above cv.LUT() attribute we can replace a pixel's value with its corresponding LUT's value<jupyter_code>%matplotlib inline
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

img = cv.imread('Lenna.png', cv.IMREAD_GRAYSCALE)

# Transformation
transform = np.arange(0,256).astype('uint8')

fig, ax = plt.subplots()
ax.plot(transform)
ax.set_title('Transformation')
ax.set_xlim(0,255)
ax.set_ylim(0,255)
ax.set_aspect('equal')

fig, ax = plt.subplots(1,3)
ax[0].imshow(img, cmap = 'gray', vmin = 0, vmax = 255)
ax[0].set_title('Original')

img2 = cv.LUT(img, transform)
ax[1].imshow(img2, cmap = 'gray', vmin = 0, vmax = 255)
ax[1].set_title('Transformed')

img3 = img - img2
ax[2].imshow(img3, cmap = 'gray', vmin = 0, vmax = 255)
ax[2].set_title('Subtracted')

plt.show()<jupyter_output><empty_output><jupyter_text>2. Negative Transform* Transformation does not change the image.* 0 maps to 255* 255 maps to 0 Additional Facts* If the value(say "a") of a pixel become minus that is a< 0, then the following value will be assigned to that pixel.```New value of the pixel = 256*((abs(a)//256)+1) + a```<jupyter_code>%matplotlib inline
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

img = cv.imread('Lenna.png', cv.IMREAD_GRAYSCALE)
#Transformation
tranform = np.arange(255, -1, -1).astype('uint8')

fig, ax = plt.subplots()
ax.plot(tranform)
ax.set_title('Transformation')
ax.set_xlim(0,255)
ax.set_ylim(0,255)
ax.set_aspect('equal')

fig, ax = plt.subplots(1,3)
ax[0].imshow(img, cmap ='gray', vmin = 0, vmax = 255)
ax[0].set_title('Original')

img2 = cv.LUT(img, tranform)
ax[1].imshow(img2, cmap = 'gray', vmin = 0, vmax = 255)
ax[1].set_title('Transformed')

img3 = img - img2

#print('Current value =', img3[222,222])
#a = -258
#print(256*((abs(a)//256)+1) + a)
#img3[200:300,200:300] = a    
#Print(img3[222,222])

ax[2].imshow(img3, cmap = 'gray', vmin = 0, vmax = 255)
ax[2].set_title('Subtracted')
plt.show()<jupyter_output><empty_output><jupyter_text>3. Intensity WindowingThe transformation has different functions over different ranges. * What matters is the number of elements in the transformation table, there must be 256 values which lies between 0 and 255.<jupyter_code>%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv

img = cv.imread('Lenna.png', cv.IMREAD_GRAYSCALE)

a, b = [40,200]

tr1 = np.linspace(0,a,93).astype('uint8')
tr2 = np.linspace(a+1,b,30).astype('uint8')
tr3 = np.linspace(b+1,255,133).astype('uint8')

transf = np.concatenate((tr1, tr2), axis = 0)
transf = np.concatenate((transf, tr3), axis = 0)

fig, ax = plt.subplots()
ax.plot(transf[::-1])
ax.set_title('transformation')
ax.set_xlim(0,255)
ax.set_ylim(0,255)
ax.set_aspect('equal')
plt.show()

fig, ax = plt.subplots(1,2)
ax[0].imshow(img, cmap ='gray', vmin = 0, vmax = 255)
ax[0].set_title('Original')

img2 = cv.LUT(img, transf[::-1])
ax[1].imshow(img2, cmap = 'gray', vmin = 0, vmax = 255)
ax[1].set_title('Transformed')
plt.show()
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv

img = cv.imread('Lenna.png', cv.IMREAD_GRAYSCALE)

x = np.arange(0,256).astype('uint8')

transf = x*5


fig, ax = plt.subplots()
ax.plot(transf)
ax.set_title('transformation')
ax.set_xlim(0,255)
ax.set_ylim(0,255)
ax.set_aspect('equal')
plt.show()

fig, ax = plt.subplots(1,2)
ax[0].imshow(img, cmap ='gray', vmin = 0, vmax = 255)
ax[0].set_title('Original')

img2 = cv.LUT(img, transf)
ax[1].imshow(img2, cmap = 'gray', vmin = 0, vmax = 255)
ax[1].set_title('Transformed')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1650602409638554, 'fraction_numerical': 0.060240963855421686, 'mean_word_length': 5.547318611987381, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '524828', 'license': 'MIT', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1658, 'n_words': 415, 'path': 'PracticeCV/IntensityTransforms.ipynb', 'repo_name': 'Ganeshgng/CV-Processing', 'size': '4150'}