Member-only story

Image Algebra

Pradeep Pujari
2 min readDec 23, 2020

How an image is seen by computer:

Digital image is a matrix of numbers of size m x n (2D array). We call size of the matrix : m x n as resolution of the image. Each pixel value can range from 0 to 255. Pixel stands for pixel elements. To simplify further, here we consider only grey images, it means there is no color channel. Below, we can print the matrix values of this cat image. For details with code, please see here

Below code prints its pixel values.

im_32 = im.resize((32,32))
display(im_32)
print('Resolution', im_32.size)

im_matrix = np.matrix(im_32) #converting image to matrix
print(im_matrix)
[[ 90 101 105 ... 101 98 89]
[ 96 104 108 ... 104 100 94]
[ 99 105 111 ... 107 102 96]
...
[ 47 56 81 ... 48 42 42]
[ 50 61 73 ... 44 43 40]
[ 49 45 60 ... 39 40 40]]

A pixel value of zero represents black and gradually increases towards bright, 255 being the brightest.

Update Operation: Since, an image is a numeric matrix, we can update pixel value(s) to any number between 0 to 255 both inclusive. But we can not update a pixel value to a negative number, all negative updates rounded to zero. Similarly, if you try to update number above 255, it updates to 255. This is because each pixel is represented as uint8 type, meaning unsigned ( can not take…

--

--

Pradeep Pujari
Pradeep Pujari

Written by Pradeep Pujari

AI Researcher, Author, Founder of TensorHealth-NewsLetter, ex-Meta

No responses yet