Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5149e7f

Browse files
Merge pull request avinashkranjan#743 from A-kriti/master
Negative/ghost image
2 parents a8ea1bb + fbed5cd commit 5149e7f

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

‎Ghost filter/Ghost filter code.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
import cv2
4+
import os.path
5+
6+
# take path of the image as input
7+
img_path = input("Enter the path here:") #example -> C:\Users\xyz\OneDrive\Desktop\project\image.jpg
8+
img = cv2.imread(img_path)
9+
image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
10+
image_small = cv2.pyrDown(img)
11+
number_iter = 5
12+
for _ in range(number_iter):
13+
image_small= cv2.bilateralFilter(image_small, d=9, sigmaColor=9, sigmaSpace=7)
14+
image_rgb = cv2.pyrUp(image_small)
15+
image_gray = cv2.cvtColor(image_rgb, cv2.COLOR_RGB2GRAY)
16+
image_blur = cv2.medianBlur(image_gray, 7)
17+
image_edge = cv2.adaptiveThreshold(image_blur, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 7, 2)
18+
image_edge = cv2.cvtColor(image_edge, cv2.COLOR_GRAY2RGB)
19+
array = cv2.bitwise_xor(image, image_edge) #taking xor between image and image_edge to get ghost filter
20+
plt.figure(figsize= (10,10))
21+
plt.imshow(array)
22+
plt.axis('off')
23+
24+
filename = os.path.basename(img_path)
25+
26+
plt.savefig("(Filtered)"+filename)
27+
plt.show() #real ghost filtered photo
458 KB
Loading[フレーム]

‎Ghost filter/Images/Real Photo.jpg

101 KB
Loading[フレーム]

‎Ghost filter/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Applying Ghost filter on an image.
2+
3+
Converting an image into ghost/negative image using OpenCv, Matplotlib and Numpy.
4+
5+
## Steps:
6+
* Firstly imported the required libraries which are Numpy, Matplotlib, Os and Cv2.
7+
* Read the input image/Real image using cv2
8+
9+
## Methods Used
10+
* Used Bilateral Filter
11+
* Followed by Median Blur
12+
* Followed by Adaptive Threshold
13+
* And at last used Bitwise Xor
14+
* Finally converted the image into ghost filter image
15+
16+
17+
## Original Image
18+
<img src="Images/Real Photo.jpg" height="300px">
19+
20+
## Ghost Filter Image
21+
<img src="Images/Ghost Filtered Image_.jpg" height="300px">
22+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /