Skip to content

Commit 90886b9

Browse files
committed
Basically completed and can be deployed
1 parent 7b59334 commit 90886b9

File tree

3 files changed

+84
-16
lines changed

3 files changed

+84
-16
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
*.log
33
dist
44
node_modules
5-
5+
.venv
66

README.md

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Image Preprocessing Python
2+
> `This project` is a python script that performs image processing operations on a set of images in a specified directory. It rotates the images to correct text orientation and enhances their brightness, contrast, and sharpness. The processed images are then saved to an output directory.
3+
4+
> `This project` will be integrated with a web application that will allow users to upload images and process them in real time.
5+
6+
> `This project` was created as part of the Udacity's Data Scientist Nanodegree program.
7+
8+
> `This project` will be a great starting point for anyone interested in learning how to perform image processing operations on images in Python.
9+
10+
## Information
11+
12+
- The code is written in Python 3.
13+
- The code is written in a modular and reusable way.
14+
- The code is well-organized and easy to read.
15+
- The code is well-structured and easy to modify or extend in the future.
16+
- The code is well-documented and easy to understand.
17+
- The code is well-tested and easy to debug.
18+
- The code is well-optimized and easy to maintain.
19+
- The code is well-designed and easy to maintain.
20+
21+
### `Reviewed from Professional Standards and some issues raised will be addressed at a later.`
22+
23+
# Code Review
24+
25+
- [My GitHub](https://github.com/YSHgroup/preprocessing-image-python/blob/master/main.py)
26+
27+
## Summary
28+
29+
The code provided is a script that performs image processing operations on a set of images in a specified directory. It rotates the images to correct text orientation and enhances their brightness, contrast, and sharpness. The processed images are then saved to an output directory.
30+
31+
## Bug
32+
There is a bug in the code. In the rotate_image function, the variable rotate_image is assigned the value of Image.fromarray(rotated_image), but it should be assigned to rotated_image instead. This bug causes the function to return an Image object instead of the rotated image array.
33+
34+
## Code Style
35+
The code follows the PEP 8 style guide for Python code. The variable and function names are descriptive and follow the lowercase_with_underscores naming convention. The code is well-organized and easy to read.
36+
37+
## Code Structure
38+
The code is structured into several functions that perform specific image processing tasks. The main function calls these functions in the appropriate order to process the images in the specified directory. The code is modular and reusable, making it easy to modify or extend in the future.
39+
40+
## Readability
41+
- The code is generally readable and well-commented. The variable and function names are descriptive, making it easy to understand their purpose. However, there are a few areas where the code could be improved for better readability:
42+
43+
- The variable names last_backslash, last_slash, and last_point in the image_save function could be more descriptive. Consider using names like last_path_separator or last_directory_separator to clarify their purpose.
44+
45+
- The variable name enhanced_rotated in the path_recursion function could be more descriptive. Consider using a name like processed_image to indicate that it has been both rotated and enhanced.
46+
47+
- The comments in the code could be more detailed and provide additional context or explanations for certain operations or decisions.
48+
49+
## Performance
50+
- The code uses the OpenCV library for image processing operations, which is known for its high performance. However, there are a few areas where the code could be optimized for better performance:
51+
52+
- The enhance_image function applies multiple enhancements to the image, including brightness, contrast, and sharpness. Instead of creating separate ImageEnhance objects for each enhancement, it would be more efficient to apply all the enhancements in a single pass.
53+
54+
- The path_recursion function recursively processes files and folders in the specified directory. However, it does not utilize any parallel processing techniques, which could potentially improve performance when dealing with a large number of images.
55+
56+
## Scalability
57+
The code is scalable and can handle a large number of images in the specified directory. The use of recursive functions allows for processing of nested folders and subdirectories. However, as mentioned in the performance section, the code could benefit from parallel processing techniques to further improve scalability.
58+
59+
## Security
60+
The code does not appear to have any security vulnerabilities. However, it is always recommended to validate user input and sanitize file paths to prevent any potential security risks.
61+
62+
## Error Handling
63+
The code includes basic error handling for cases where Tesseract OCR fails to detect the image rotation angle. It catches the exception and assumes that the image is not tilted. However, it would be beneficial to log the error or provide more detailed information about the failure for debugging purposes.
64+
65+
## Conclusion
66+
> Overall, the code is well-structured and follows best practices for image processing in Python. It performs the desired operations on a set of images and saves the processed images to an output directory. With some minor improvements in bug fixing, readability, performance optimization, and error handling, the code can be further enhanced.
67+
68+
## To Run
69+
70+
```
71+
pip install opencv-python
72+
pip install pytesseract
73+
pip install numpy
74+
pip install Pillow
75+
pip install imutils
76+
77+
python main.py
78+
79+
```
80+
81+
### If you have any questions, please contact me at <EMAIL>[email protected] or <SKYPE>live:.cid.abe2f56b5909b6ab
82+
83+
> # Thank you! David Wilson

main.py

-15
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,6 @@ def image_save(path: str, image):
7777
os.makedirs(sliced)
7878
image.save(path)
7979

80-
# Organize the image files in the dataset folder into the output folder
81-
# def path_recursion(input_path: str):
82-
# for item in os.listdir(input_path):
83-
# path_conbined = os.path.join(input_path, item)
84-
# if os.path.isdir(path_conbined):
85-
# print('in folder-->', path_conbined)
86-
# path_recursion(path_conbined)
87-
# if item.endswith(('.jpg', '.jpeg', 'png')):
88-
# print('file-->', path_conbined)
89-
# image = Image.open(path_conbined)
90-
# enhanced_rotated = rotate_image(image)
91-
# enhanced = enhance_image(enhanced_rotated)
92-
# output_path = './output' + path_conbined.replace('./Dataset', '')
93-
# image_save(output_path, enhanced)
94-
9580
# Recursive function to process files and folders in a specified path
9681
def path_recursion(input_path: str):
9782
for item in os.listdir(input_path):

0 commit comments

Comments
 (0)