-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue22 : restructured the image-processing module. #30
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2633c60
created morphological preprocessing file
Shankhanil c1c6895
restructured codebase: intelligent image preprocessing
Shankhanil bfadcd6
Update image_visualize.py
Sibasish-Padhy a8d2bf8
Update image_visualize.py
Sibasish-Padhy 4dd0dac
Update image_visualize.py
Sibasish-Padhy 457fd7c
Update image_visualize.py
Sibasish-Padhy ca556a3
Update image_visualize.py
Sibasish-Padhy 983d617
Update image_visualize.py
Sibasish-Padhy bd33030
Update image_visualize.py
Sibasish-Padhy 4776bb5
Update image_visualize.py
Sibasish-Padhy 2e024fc
Update image_visualize.py
Sibasish-Padhy bcc56f4
Update image_visualize.py
Sibasish-Padhy 6bbe76f
Update image_visualize.py
Sibasish-Padhy 51b9200
Refactor the code to the standards
c2a82cc
Added the standardisation function (#29)
ashish-hacker 8b73215
resolved conflicts
Shankhanil 9903dab
resolved conflict in csv_preprocess
Shankhanil b80fd1d
removed file
Shankhanil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Image Visualize | ||
========================= | ||
|
||
.. automodule:: klar_eda.visualize.image_visualize | ||
:members: | ||
:undoc-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ klar-eda's documentation! | |
|
||
preprocess | ||
visualize | ||
image_visualize | ||
|
||
|
||
Indices and tables | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,13 @@ def fill_numerical_na(self, ret = False): | |
self.df[col] = y | ||
except Exception as e: | ||
pass | ||
<<<<<<< HEAD | ||
if ret == True: | ||
return self.df | ||
======= | ||
if ret == True: | ||
return self.df | ||
>>>>>>> issue22 | ||
|
||
def fill_categorical_na(self, ret = False): | ||
self.df = self.df.fillna("Unknown") | ||
|
@@ -84,6 +89,25 @@ def normalize_numerical(self): | |
for col in self.numerical_column_list: | ||
if col != self.target_column: | ||
self.df[col]=(self.df[col]-self.df[col].min())/(self.df[col].max()-self.df[col].min()) | ||
def standardize(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file from the PR to avoid any conflicts. |
||
|
||
### Data use cases for Standardization: ### | ||
|
||
# It makes the data with unit variance and zero mean. | ||
# This will be used when the features have different scales , for example if there are two features salary and age , Obviously age will be from 1-100 and salary can be substantially higher than age values. So if we fit the model directly the salary feature will have a larger impact on predicting the target variable. But it may not be the case. | ||
# So It's necessary to standardise the data. | ||
# We should do standardization in case of algorithms where Gradient descent is used for optimizations, for achieving the minima faster. | ||
# Standardisation is also called z-score normalisation. | ||
|
||
for i in df.columns: | ||
self.df[i] = (self.df[i] - self.df[i].mean())/self.df[i].std() # Standardise the data z = (x - mean)/ (standard deviation) | ||
|
||
def mean_normalization(self): | ||
""" converts x to x' where, | ||
x' = (x - mean(x))/(max(x) - min(x)) | ||
""" | ||
for col in df.columns: | ||
self.df[i] = (self.df[i] - self.df[i].mean())/(self.df[i].max() - self.df[i].min()) | ||
|
||
def encode_categorical(self): | ||
enc = OneHotEncoder(handle_unknown='ignore') | ||
|
@@ -160,4 +184,4 @@ def convert_date_format(self, input_date, output_date_format = 'DD/MM/YYYY'): | |
|
||
parsed_date = dateutil.parser.parse(input_date, dayfirst=True) | ||
self.converted_date = parsed_date.strftime(output_date_formats[output_date_format]) | ||
return self.converted_date | ||
return self.converted_date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import morphological | ||
from . import intelligent | ||
import pkg_resources | ||
pkg_resources.declare_namespace(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
from os import makedirs | ||
from os.path import join, exists | ||
import numpy as np | ||
import cv2 | ||
import matplotlib.pyplot as plt | ||
import matplotlib.image as mpimg | ||
from ..image_preprocess import ImagePreprocess | ||
|
||
class IntelligentImagePreprocess: | ||
""" | ||
This class contains the functions: | ||
|
||
""" | ||
def __init__(self,input,labels = None): | ||
self.suffixes = ('.jpeg', '.jpg', '.png') | ||
# self.clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) | ||
self.labels = labels | ||
if type(input)==str: | ||
self.path = input | ||
self.image_list = sorted([ file for file in os.listdir(input) if (file.endswith(self.suffixes))]) | ||
self.cv2_image_list = [ self.read_images(os.path.join(self.path,image_name)) for image_name in self.image_list ] | ||
else: | ||
self.path = None | ||
self.image_list = None | ||
self.cv2_image_list = input | ||
|
||
# the functions | ||
def detect_face_and_crop(self, crop = False, save=True, show=False): | ||
face_image_list = [] | ||
image_index = -1 | ||
face_cascade = self.get_cascade('face') | ||
for image in self.cv2_image_list: | ||
try: | ||
image_index += 1 | ||
img = image.copy() | ||
faces = face_cascade.detectMultiScale(img, 1.3, 5) | ||
if faces is None: | ||
print('Unable to find face ') | ||
continue | ||
for (x,y,w,h) in faces: | ||
padding = 10 | ||
ih, iw = img.shape[:2] | ||
lx = max( 0, x - padding ) | ||
ly = max( 0, x - padding ) | ||
ux = min( iw, x + w + padding ) | ||
uy = min( ih, y + h + padding ) | ||
img = cv2.rectangle(img,(lx,ly),(ux,uy),(255,0,0),2) | ||
roi_color = img[y:y+h, x:x+w] | ||
if crop == True: | ||
self.save_or_show_image(roi_color, image_index, 'haarcascade_faces',save=save,show=show) | ||
self.save_or_show_image(img, image_index, 'haarcascade',save=save,show=show) | ||
face_image_list.append(img) | ||
except Exception as e: | ||
print('Error while detecing') | ||
self.cv2_image_list = face_image_list |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conflict seems not resolved yet