0% found this document useful (0 votes)
15 views14 pages

16 16 Int Range 16 Range 16: Import As Import As For in For in

Uploaded by

Dounia Grari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views14 pages

16 16 Int Range 16 Range 16: Import As Import As For in For in

Uploaded by

Dounia Grari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

import numpy as np

import matplotlib.pyplot as plt


A = np.zeros((16, 16), dtype=int)
for i in range(16):
for j in range(16):
A[i, j] = i * j
plt.imshow(A, cmap='gray')
plt.colorbar()
plt.show()

import numpy as np
import matplotlib.pyplot as plt

B = np.zeros((128, 128), dtype=int)


for i in range(128):
for j in range(128):
B[i, j] = i + j
plt.imshow(B, cmap='gray')
plt.colorbar()
plt.title("Matrice 128x128 ")
plt.xlabel("Colonnes")
plt.ylabel("Lignes")
plt.show()
import numpy as np
import matplotlib.pyplot as plt

C = np.zeros((32, 32, 3), dtype=np.uint8)


C[:, :, 0] = 255
C[16, :, 0] = 255
C[16, :, 1] = 185
C[16, :, 2] = 15

plt.imshow(C)
plt.title("Matrice C ")
plt.axis("off")
plt.show()
import matplotlib.pyplot as plt
from skimage import io

image_path = 'lena1.jpg'
A = io.imread(image_path, as_gray=True)
colormaps = [
'gist_yarg', 'spring', 'gray', 'pink', 'gist_heat',
'cool', 'hot', 'afmhot' ]
plt.figure(figsize=(15, 15))
for i, cmap in enumerate(colormaps, start=1):
plt.subplot(4, 4, i)
plt.imshow(A, cmap=cmap)
plt.title(cmap)
plt.axis('off')

plt.tight_layout()
plt.show()
img = io.imread("Coucher.jpg")
red_channel = img[:, :, 0]
green_channel = img[:, :, 1]
blue_channel = img[:, :, 2]

plt.figure(figsize=(10, 4))
plt.subplot(1, 3, 1)
plt.imshow(red_channel, cmap='gray')
plt.title("Canal Rouge")

plt.subplot(1, 3, 2)
plt.imshow(green_channel, cmap='gray')
plt.title("Canal Vert")

plt.subplot(1, 3, 3)
plt.imshow(blue_channel, cmap='gray')
plt.title("Canal Bleu")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from skimage import io

img = io.imread("texte.bmp", as_gray=True)


profilH = img[img.shape[0] // 2, :]
profilV = img[:, img.shape[1] // 2]

plt.figure(0)
plt.plot(profilV, label="Profil vertical")
plt.title("Profil vertical")
plt.xlabel("la colonne")
plt.ylabel("Intensité")
plt.legend()

plt.figure(1)
plt.plot(profilH, label="Profil horizontal")
plt.title("Profil horizontal")
plt.xlabel(" la ligne")
plt.ylabel("Intensité")
plt.legend()

plt.show()
projectionHorizontale = np.sum(img, axis=0)
projectionVerticale = np.sum(img, axis=1)

plt.figure(2)
plt.plot(projectionHorizontale, label="Projection horizontale")
plt.title("Projection horizontale")
plt.xlabel("Colonnes")
plt.ylabel("Somme des intensités")
plt.legend()

plt.figure(3)
plt.plot(projectionVerticale, label="Projection verticale")
plt.title("Projection verticale")
plt.xlabel("Lignes")
plt.ylabel("Somme des intensités")
plt.legend()

plt.show()
import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('uro_irm.jpg', cv2.IMREAD_GRAYSCALE)


myhist, bins = np.histogram(img.ravel(), 256, [0, 255])

plt.hist(img.ravel(), 256, [0, 256])


plt.title('Histogramme de l\'image')
plt.show()
import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('lena1.jpg', cv2.IMREAD_GRAYSCALE)


myhist, bins = np.histogram(img.ravel(), 256, [0, 255])

plt.hist(img.ravel(), 256, [0, 256])


plt.title('Histogramme de l\'image')
plt.show()
import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('lena1.jpg', cv2.IMREAD_GRAYSCALE)


img_added = cv2.add(img, 50)
img_subtracted = cv2.subtract(img, 50)

plt.figure(figsize=(12, 6))

plt.subplot(3, 2, 1)
plt.imshow(img, cmap='gray')
plt.title('Image originale')

plt.subplot(3, 2, 2)
plt.hist(img.ravel(), 256, [0, 256])
plt.title('Histogramme original')

plt.subplot(3, 2, 3)
plt.imshow(img_added, cmap='gray')
plt.title('Image après ajout')

plt.subplot(3, 2, 4)
plt.hist(img_added.ravel(), 256, [0, 256])
plt.title('Histogramme après ajout')

plt.subplot(3, 2, 5)
plt.imshow(img_subtracted, cmap='gray')
plt.title('Image après soustraction')

plt.subplot(3, 2, 6)
plt.hist(img_subtracted.ravel(), 256, [0, 256])
plt.title('Histogramme après soustraction')

plt.tight_layout()
plt.show()

import cv2
import numpy as np
import matplotlib.pyplot as plt

img_obama = cv2.imread('obama.jpg', cv2.IMREAD_GRAYSCALE)


img_obama2 = cv2.imread('obama2.jpeg', cv2.IMREAD_GRAYSCALE)

plt.figure(figsize=(12, 6))
plt.subplot(2, 2, 1)
plt.hist(img_obama.ravel(), 256, [0, 256])
plt.title('Histogramme - Obama')
plt.subplot(2, 2, 2)

plt.hist(img_obama2.ravel(), 256, [0, 256])


plt.title('Histogramme - Obama2')

mean_obama = np.mean(img_obama)
std_dev_obama = np.std(img_obama)
variance_obama = np.var(img_obama)

mean_obama2 = np.mean(img_obama2)
std_dev_obama2 = np.std(img_obama2)
variance_obama2 = np.var(img_obama2)

contrast_obama = (np.max(img_obama) - np.min(img_obama)) /


(np.max(img_obama) + np.min(img_obama))
contrast_obama2 = (np.max(img_obama2) - np.min(img_obama2)) /
(np.max(img_obama2) + np.min(img_obama2))

print(f"Image Obama:")
print(f" - NdG moyen: {mean_obama}")
print(f" - Variance: {variance_obama}")
print(f" - Ecart-type: {std_dev_obama}")
print(f" - Constraste (C): {contrast_obama}")

print(f"\nImage Obama2:")
print(f" - NdG moyen: {mean_obama2}")
print(f" - Variance: {variance_obama2}")
print(f" - Ecart-type: {std_dev_obama2}")
print(f" - Constraste (C): {contrast_obama2}")
plt.tight_layout()
plt.show()

<ipython-input-15-0ec749407653>:26: RuntimeWarning: overflow


encountered in scalar add
contrast_obama2 = (np.max(img_obama2) - np.min(img_obama2)) /
(np.max(img_obama2) + np.min(img_obama2))

Image Obama:
- NdG moyen: 82.69898062136868
- Variance: 4582.040060309138
- Ecart-type: 67.69076791047017
- Constraste (C): 1.0

Image Obama2:
- NdG moyen: 126.36594407530454
- Variance: 386.5990057532402
- Ecart-type: 19.662121089883467
- Constraste (C): 4.6
import cv2
import numpy as np
import matplotlib.pyplot as plt

img = cv2.imread('texte.bmp')
img_inverted = 255 - img

plt.subplot(1, 2, 1)
plt.imshow(img, cmap='gray')
plt.title("Image originale (NdG)")

plt.subplot(1, 2, 2)
plt.imshow(img_inverted, cmap='gray')
plt.title("Image inversée (NdG)")

plt.show()

You might also like