TP: Introduction to image processing - Radiometry

1. Introduction

For the following exercices, you need to have an install of Python 3 with numpy and matplotlib.

You need first to download the file TP.zip which contains the images you need for the session, and to put these images in the same directory as your python file.

2. Load and display a color image.

A color image u is made of three channels : red, green and blue. A color image in ℝN×M is stored as a N×M×3 matrix.

Image load

In [130]:
import matplotlib.pyplot as plt
%matplotlib inline
imrgb =plt.imread("../im/parrot.png")

#the image is of type int, we cast it in float in order to do computations
imrgb=imrgb.astype(float)

# extract the three (red,green,blue) channels from y
imred   = imrgb[:,:,0]
imgreen = imrgb[:,:,1]
imblue  = imrgb[:,:,2]

#image size 
[nrow,ncol,nch]=imrgb.shape
print(nrow,ncol,nch)

plt.imshow(imrgb)
495 495 3
Out[130]:
<matplotlib.image.AxesImage at 0x129ba3668>

Image display

In [40]:
#we display an image thanks to the function imshow of the pyplot library of matplotlib
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10, 10))

#we display the images
axes[0, 0].imshow(imrgb)
axes[0,0].set_title('Original image')
axes[0, 1].imshow(imred, cmap="gray")
axes[0,1].set_title('red channel')
axes[1, 0].imshow(imgreen, cmap="gray")
axes[1,0].set_title('green channel')
axes[1, 1].imshow(imblue, cmap="gray")
axes[1,1].set_title('blue channel')
fig.tight_layout()