0% found this document useful (0 votes)
45 views9 pages

TP Vision 3

The document presents a Python code that implements the Nagao filter to reduce noise in images by comparing variance values of pixels within local neighborhoods and replacing the center pixel with the mean value of the neighborhood with minimum variance, the code loads an image, adds random noise, calculates pixel neighborhoods, compares variances, replaces pixels to output a filtered image.
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)
45 views9 pages

TP Vision 3

The document presents a Python code that implements the Nagao filter to reduce noise in images by comparing variance values of pixels within local neighborhoods and replacing the center pixel with the mean value of the neighborhood with minimum variance, the code loads an image, adds random noise, calculates pixel neighborhoods, compares variances, replaces pixels to output a filtered image.
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/ 9

Université KASDI-MERBAH Ouargla

Faculté de Technologies

Département d'electronique et de télécommunication

Niveau : Master 2 Electronique Systeme Embarque

Module : Vision Artficielle

TP N°3 :Image Histogramme and


Féltering

❖ Présenté par :

- Benkhira Belkhir
Assignment:01
The Nagao filtre python code.

importcv2
import numpy as np
img=cv2.imread(r'D:\tppicture\FB_IMG_1629707635017
6943.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
height,width=gray.shape
img_noise=np.zeros_like(gray)
for I in range(height):
for j in range(width):
make_noise=np.random.normal ()
set_noise=10*make_noise
img_noise[i][j]=gray[i][j]+set_noise
out=np.zeros((height+4,width+4),dtype=np.float)
out[2:2+height,2:2+width]=img_noise.copy().astype(np.fl
oat)
foriinrange(height):
:(forjinrange(width (
point1=np.ravel(out[i+1:i+4,j:j+2])
point1=np.append(point1,out[i+2,j+2])
point2=np.ravel(out[i+3:i+5,j+1:j+4])
point2=np.append(point2,out[i+2,j+2])
point3=np.ravel(out[i+1:i+4,j+3:j+5])
point3=np.append(point3,out[i+2,j+2])
point4=np.ravel(out[i:i+2,j+1:j+4])
point4=np.append(point4,out[i+2,j+2])
point5=np.ravel(out[i:i+2,j:j+2])
point5=np.append(point5,out[i+2,j+1])
point5=np.append(point5,out[i+1,j+2])
point5=np.append(point5,out[i+2,j+2])
point6=np.ravel(out[i+3:i+5,j:j+2 ])
point6=np.append(point6,out[i+2,j+1])
point6=np.append(point6,out[i+3,j+2])
point6=np.append(point6,out[i+2,j+2])
point7=np.ravel(out[i+3:i+5,j+3:j+5 ])
point7=np.append(point7,out[i+2,j+3])
point7=np.append(point7,out[i+3,j+2])
point7=np.append(point7,out[i+2,j+2])
point8=np.ravel(out[i:i+2,j+3:j+5])
point8=np.append(point8,out[i+1,j+2])
point8=np.append(point8,out[i+2,j+3 ])
point8=np.append(point8,out[i+2,j+2])
if min (np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7),np.var(point8))==np.var(point1):
out[2+i,2+j]=np.mean(point1)
elif min (np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7), np.var(point8))==np.var(point2):
out[2+i,2+j]=np.mean(point2)
elif min (np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7),np.var(point8))==np.var(point3):
out[2+i,2+j]=np.mean(point3)
elif min (np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7),np.var(point8))==np.var(point4):
out[2+i,2+j]=np.mean(point4)

elif min(np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7),np.var(point8))==np.var(point5):
out[2+i,2+j]=np.mean(point5)
elif min (np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7),np.var(point8))==np.var(point6):
out[2+i,2+j]=np.mean(point6)
elif min (np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7),np.var(point8))==np.var(point7):
out[2+i,2+j]=np.mean(point7)
elif min(np.var(point1),np.var(point2),
np.var(point3),np.var(point4),np.var(point5),np.var(point
6),np.var(point7),np.var(point8))==np.var(point8):
out[2+i,2+j]=np.mean(point8)
out=out[2:2+height,2:2+width].astype(np.uint8)

cv2.imshow('original',gray)
cv2.imshow('noise',img_noise)
cv2.imshow('out',out)
cv2.waitKey(0)
Assignment:02
A python code can convert a gray image as:

Import cv as cv2
Import numpy as np
From matplotlib import pyplot as plt
Img=Cv2.imread(‘old gray image’)
LUT=np.array([0, 100, 200, 255])
For I in range(256);
Print(“&d→&d”%(I,LUT[I]))
Plt.figure()
Plt.plot(range(256),LUT, ’b+-)
Plt.show()
0→0
50→200
100→100
150→100
200→200
255→255
Im=Cv2.imshow(‘new gray image’)
Print(I’m.shape)
Plt.figure()
Imshow(I’m)
Plt.show ()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy