Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Feature: adding image filters scritps #337

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions Image-Processing/Multi Filters Include Negative/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Multi Filters Include Negative

The multi filters provides eleven differents filters to apply on images. It includes the Blur effect, Contour, Detail, Edge enhance and the Edge enhance more, Emboss, Find_egdes, Sharpen, Smooth and the Smooth_more and the Negative effect

## Installing dependences

First of all, we should check if we are using an updated version of pip, with this line:

`python3 -m pip install --upgrade pip`

Now, we need to install Pillow library to support images on Python:

`python3 -m pip install --upgrade Pillow`

Then, the opencv library help us with computer vision, providing us with functions to apply filters:

`pip install opencv-python`

Others dependences that we are going to need are matplotlib, to display the images and for that we need to install numpy:

`pip install numpy`

and then install matplotlib:

`matplotlib: python -m pip install -U matplotlib`

note that matplotlib may install numpy as a dependence, but is a good practice to do it manually

## Running

To get the program running we use the command below:

`python filters.py [NAME OF FILE IMAGE]`

It will show us the image we chosen and open a menu with the filters, from which we got to write a number corresponding to the filter we would like

## Example

Let's try out with a normal image of an apple
<p align="center">
<img src="apple.jpg" width="250" height="250">
</p>

Applying each of the filters, we get the following results:

1 - Blur filter
<p align="center">
<img src="./images/apple_1_converted.jpg" width="250" height="250">
</p>

2 - Contour filter
<p align="center">
<img src="./images/apple_2_converted.jpg" width="250" height="250">
</p>

3 - Detail filter
<p align="center">
<img src="./images/apple_3_converted.jpg" width="250" height="250">
</p>

4 - Edge enhance filter
<p align="center">
<img src="./images/apple_4_converted.jpg" width="250" height="250">
</p>

5 - Edge enhance more filter
<p align="center">
<img src="./images/apple_5_converted.jpg" width="250" height="250">
</p>

6 - Emboss filter
<p align="center">
<img src="./images/apple_6_converted.jpg" width="250" height="250">
</p>

7 - Find_egdes filter
<p align="center">
<img src="./images/apple_7_converted.jpg" width="250" height="250">
</p>

8 - Sharpen filter
<p align="center">
<img src="./images/apple_8_converted.jpg" width="250" height="250">
</p>

9 - Smooth filter
<p align="center">
<img src="./images/apple_9_converted.jpg" width="250" height="250">
</p>

10 - Smooth_more filter
<p align="center">
<img src="./images/apple_10_converted.jpg" width="250" height="250">
</p>

11 - Negative filter
<p align="center">
<img src="./images/apple_11_converted.jpg" width="250" height="250">
</p>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions Image-Processing/Multi Filters Include Negative/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from PIL import Image
from PIL import ImageFilter
import matplotlib.pyplot as plt
import negative_image
import cv2
import sys
import os

# Loading images
if len(sys.argv) == 2:
fn_with_ext = sys.argv[1]
filename, file_extension = os.path.splitext(sys.argv[1])
else:
print("No input image given, so loading default image, lena.jpg \n")
print("Correct Usage: python grabcut.py <filename> \n")

# Insert path here
img = Image.open(fn_with_ext)
img = img.convert('RGB')

plt.imshow(img)
plt.show()

# List of Filters (is selected in menu option)
filters = [ImageFilter.BLUR, ImageFilter.CONTOUR, ImageFilter.DETAIL, ImageFilter.EDGE_ENHANCE, ImageFilter.EDGE_ENHANCE_MORE, ImageFilter.EMBOSS, ImageFilter.FIND_EDGES, ImageFilter.SHARPEN, ImageFilter.SMOOTH, ImageFilter.SMOOTH_MORE]

while True:
try:
print("MENU OF FILTERS IMAGE APPLICATION", end=" ")
print("(CHOOSE A OPTION BELLOW TO FILTER AN IMAGE):")

print("1- BLUR")
print("2- CONTOUR")
print("3- DETAIL")
print("4- EDGE_ENHANCE")
print("5- EDGE_ENHANCE_MORE")
print("6- EMBOSS")
print("7- FIND_EDGES")
print("8- SHARPEN")
print("9- SMOOTH")
print("10- SMOOTH_MORE")
print("11- NEGATIVE")
print("Ctr+D FOR EXIT")

opt = None
while True:
try:
opt = int(input())
if (opt >= 1 and opt <= 11):
break
except ValueError:
print("PLEASE, DIGIT A INTEGER NUMBER BETWEEN 1 AND 11")

if (opt >= 1 and opt <= 10):
img1 = img.filter(filters[opt-1])
img1.save(f"./images/{filename}_{opt}_converted{file_extension}", "JPEG")
else:
img1 = negative_image.negative(fn_with_ext)
cv2.imwrite(f"./images/{filename}_{opt}_converted{file_extension}", img1)

plt.imshow(img1)
plt.show()
except EOFError:
break
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import cv2

def negative(image):
img_bgr = cv2.imread(image, 1)

img_neg = 255 - img_bgr

return img_neg