https://github.com/aman9026/custom-filters
Simple guide with code snippets for creating Custom-Filters by Image-Processing
https://github.com/aman9026/custom-filters
digital-image-processing filter filters guide image-processing mlops numpy numpy-arrays opencv python3 tutorial tutorial-code
Last synced: 20 days ago
JSON representation
Simple guide with code snippets for creating Custom-Filters by Image-Processing
- Host: GitHub
- URL: https://github.com/aman9026/custom-filters
- Owner: Aman9026
- Created: 2020-04-09T08:12:35.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-19T07:05:32.000Z (about 5 years ago)
- Last Synced: 2025-02-08T17:10:26.428Z (2 months ago)
- Topics: digital-image-processing, filter, filters, guide, image-processing, mlops, numpy, numpy-arrays, opencv, python3, tutorial, tutorial-code
- Homepage: https://github.com/Aman9026/Custom-Filters
- Size: 884 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# ImageProcessing

***You are always welcome to optimize or improve any resource in this repository by following [these](https://github.com/Aman9026/ImageProcessing/blob/master/CONTRIBUTING.md) instructions.***
---
**Images:** 2-D representation of the visible light spectrum
```
Human visual system(eye & visual cortex) is incredibly good at image processing
```**Color Spaces:** different method to store image in computer (eg, RGB, HSV, CMYK)
**OpenCV:** Open source Computer Vision Software for image processing, OpenCV default color space is RGB, but stores color in BGR format, to improve processing of image operation
**HSV:** hue, saturation and value/brightness , is a color space that attempts to represent colors the way humans perceive it, in CV we use for color segmentation
## Installation
Install OpenCV by Anaconda:
```conda install opencv```Install by python installer pip:
```pip install opencv-python```## Adding filters
We can add inbuilt filters or create custom filters by ourself, We'll incorporate both here.***Original Image:***
**Now let's add filters to it.**
Import module opencv
```
>>> import cv2
```OpenCV load image from storage and convert into numpy array:
```
>>> photo = cv2.imread('imagename.jpg')
```
**We don't need to load numpy module, opencv call its internal property.**Convert image into gray image:
```>>> gray_image = cv2.cvtColor(photo , cv2.COLOR_BGR2GRAY)```
Show image, but we have use waitKey() and destroyAllWindows() with imshow(), otherwise program will hang up
```
>>> cv2.imshow('image title', photo)
>>> cv2.waitKey()
>>> cv2.destroyAllWindows()
```**waitkey():** used to hold windows for some time interval, and also wait for any key input from keyword, so listen key and then go to next statement
**destroyAllWindows():** close any window, open by imshow()

A very faster alternative of adding filter by inbuilt functions is by doing it manually in an optimized way.
We can convert the image to gray while reading only by a simple trick given below.
```
>>> grey_photo = cv2.imread('image.jpg' , 0)```
## Remove or Amplify a color from image
Split Color from colorful image:
```>>> B, G, R = cv2.split(photo)```
```
>>> import numpy as np
>>> height = photo.shape[0]
>>> width = photo.shape[1]
>>> zero = np.zeros((height, width))>>> cv2.merge([zero, G, R])
```It give error because, array of image require datatype “**unit8**” but zero function create datatype float
```
>>>B.dtype
dtype('uint8')
```What is uint, 8-bit unsigned, here 8 is 8 bit, means 2^8 = 0-255 number we can store in it.
So if u store “1000”, it won't store this:
```>>> photo[0][0][0] = "1000"``````
>>> zero.dtype
dtype('float64')
```
```
>>> zero_unit8 = zero.astype('uint8')
>>> new_photo_B_removed = cv2.merge([zero_unit8, G, R])
```
```
>>> cv2.imshow('image title', new_photo_B_removed)
>>> cv2.waitKey()
>>> cv2.destroyAllWindows()
```**If we want to amplify any color in image, let say green color :**
```
>>> new_photo_B_removed = cv2.merge([zero_unit8, G+100, R])
```**Same thing done by the code explained above can be done in one line like this:**
If we want to remove all the colour except **Red**
```>>> photo[:,:,0:2] = 0```

## Custom filters
I created a custom filter similar to "**ambience**" in popular photo editing applications.Just amplified BLUE and GREEN by 100 without changing RED.
