Skip to content

Commit 0b827dc

Browse files
authored
WIP #7: Basic Script for Removing Perceived Noise
"Perceived noise" used rather generously; this script compares the standard deviation of a pixel over a set of images and sets any that don't have a standard deviation of 0 to be white (grayscale value 255).
1 parent 985cd4d commit 0b827dc

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

vision/ImageCompareTest.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# This script compares a list of images and looks for any pixel whose standard
2+
# deviation over the set of pixels at that point is greater than 0, then sets it
3+
# to be white (255). It is for grayscale images, and runs slowly over large
4+
# images.
5+
6+
import cv2
7+
import numpy as np
8+
9+
imgArr = []
10+
11+
# NOTE: I did not upload the test images I used to the GitHub, because the
12+
# specific images used does not matter so long as they are grayscale.
13+
# Anyone can make images with paint (or just ask Daniel for the images).
14+
15+
# Only ever have one set uncommented at once
16+
#First set of test images - small
17+
#img1 = cv2.imread ("TestImage1.png")
18+
#img2 = cv2.imread ("TestImage2.png")
19+
#img3 = cv2.imread ("TestImage3.png")
20+
#img4 = cv2.imread ("TestImage4.png")
21+
#img5 = cv2.imread ("TestImage5.png")
22+
23+
#Second set of test images - medium
24+
img1 = cv2.imread ("TI6.png")
25+
img2 = cv2.imread ("TI7.png")
26+
img3 = cv2.imread ("TI8.png")
27+
img4 = cv2.imread ("TI9.png")
28+
img5 = cv2.imread ("TI10.png")
29+
30+
#Third set of test images - large
31+
#img1 = cv2.imread ("TI11.png")
32+
#img2 = cv2.imread ("TI12.png")
33+
#img3 = cv2.imread ("TI13.png")
34+
#img4 = cv2.imread ("TI14.png")
35+
#img5 = cv2.imread ("TI15.png")
36+
37+
#Just in case the images aren't actually grayscale
38+
#gray1 = cv2(img1, cv2.COLOR_BGR2GRAY)
39+
#gray2 = cv2(img2, cv2.COLOR_BGR2GRAY)
40+
#gray3 = cv2(img3, cv2.COLOR_BGR2GRAY)
41+
#gray4 = cv2(img4, cv2.COLOR_BGR2GRAY)
42+
#gray5 = cv2(img5, cv2.COLOR_BGR2GRAY)
43+
44+
#imgArr.append(gray1)
45+
#imgArr.append(gray2)
46+
#imgArr.append(gray3)
47+
#imgArr.append(gray4)
48+
#imgArr.append(gray5)
49+
50+
51+
imgArr.append(img1)
52+
imgArr.append(img2)
53+
imgArr.append(img3)
54+
imgArr.append(img4)
55+
imgArr.append(img5)
56+
57+
numImgs = 5 # numImgs is the number of images used to test
58+
pixArr = [None] * numImgs
59+
60+
leadImg = imgArr[0] #Uses img1 as a basis for iterating
61+
height, width = leadImg.shape[:2]
62+
for i in range(0, height): #Iterates through entire image
63+
for j in range(0,width):
64+
for k in range (0,numImgs):
65+
pixArr[k] = imgArr[k][i,j]
66+
if np.std(pixArr) > 0:
67+
leadImg[i,j] = 255
68+
69+
# To reduce clutter, you can comment out all the cv2.imshow lines besides
70+
# 'Adjusted.'
71+
cv2.imshow('Img1', imgArr[0]) # Possible concern? img1 is adjusted because
72+
cv2.imshow('Img2', imgArr[1]) # leadImg also accesses it
73+
cv2.imshow('Img3', imgArr[2])
74+
cv2.imshow('Img4', imgArr[3])
75+
cv2.imshow('Img5', imgArr[4])
76+
cv2.imshow('Adjusted', leadImg)
77+
cv2.waitKey(0)
78+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)