Vela commited on
Commit
ab2b59d
·
1 Parent(s): 8649638

created project

Browse files
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .venv
2
+ temp
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from src.app import image_conversion
4
+
5
+ st.title("Image Processer")
6
+
7
+ uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
8
+ if uploaded_file:
9
+ image = Image.open(uploaded_file)
10
+ if image.height > image.width:
11
+ st.image(image, caption="Uploaded Portrait Image", width=500)
12
+ else:
13
+ st.image(image, caption="Uploaded Image", width=500)
14
+
15
+ file_path = image_conversion.get_file_path(uploaded_file)
16
+ selected_option = st.selectbox("Choose the following",["","Rotate","Change to RGB", "Change to BGR", "Change to Grayscale","Increase Brightness"])
17
+ option = selected_option.replace(" ","_").lower()
18
+ image_conversion.display_converted_image(st, option, file_path)
19
+
20
+
21
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ opencv-python
src/app/__pycache__/image_conversion.cpython-313.pyc ADDED
Binary file (2.31 kB). View file
 
src/app/image_conversion.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ..modules import home_page
2
+ import os
3
+
4
+
5
+ def get_file_path(uploaded_file):
6
+ if not os.path.exists("temp"):
7
+ os.makedirs("temp")
8
+ file_path = os.path.join("temp", uploaded_file.name)
9
+ with open(file_path, "wb") as f:
10
+ f.write(uploaded_file.getbuffer())
11
+ return file_path
12
+
13
+ def display_converted_image(st, option, file_path):
14
+
15
+ if option =="change_to_rgb":
16
+ file = home_page.change_image_color_format(file_path,"RGB")
17
+ st.image(file, width=500)
18
+ elif option == "change_to_bgr":
19
+ file = home_page.change_image_color_format(file_path,"BGR")
20
+ st.image(file, width=500)
21
+ elif option == "change_to_grayscale":
22
+ file = home_page.change_image_color_format(file_path,"Grayscale")
23
+ st.image(file, width=500)
24
+ elif option == "rotate":
25
+ angle = st.slider("Select Rotation Angle", min_value=0, max_value=360, value=0, step=1)
26
+ if angle:
27
+ file = home_page.change_image_color_format(file_path,"Rotate",angle)
28
+ st.image(file, width=500)
29
+ elif option == "increase_brightness":
30
+ brightness_factor = st.slider("Select Brightness Factor", min_value=0.5, max_value=3.0, value=1.2, step=0.1)
31
+ file = home_page.change_image_color_format(file_path,"increase_brightness",factor=brightness_factor)
32
+ st.image(file, caption="Brightened Image", width=500)
33
+
src/modules/__pycache__/home_page.cpython-313.pyc ADDED
Binary file (2.39 kB). View file
 
src/modules/home_page.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+
4
+ def change_image_color_format(file_path, format_type, angle=0,factor=1.5):
5
+ img = cv2.imread(file_path)
6
+
7
+ if format_type.lower() == 'rgb':
8
+ img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
9
+ return img_rgb
10
+ elif format_type.lower() == 'bgr':
11
+ img_bgr = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
12
+ return img_bgr
13
+ elif format_type.lower() == 'grayscale':
14
+ grayscale_img = cv2.cvtColor(img, cv2.IMREAD_GRAYSCALE)
15
+ return grayscale_img
16
+ elif format_type.lower() == 'rotate':
17
+ if angle != 0:
18
+ img = rotate_image(img, angle)
19
+ return img
20
+ elif format_type == "increase_brightness":
21
+ brightened_img = increase_brightness(img, factor)
22
+ return brightened_img
23
+
24
+
25
+ # Function to rotate an OpenCV image (numpy.ndarray)
26
+ def rotate_image(image, angle):
27
+
28
+ (h, w) = image.shape[:2]
29
+ center = (w // 2, h // 2)
30
+
31
+ M = cv2.getRotationMatrix2D(center, angle, 1.0)
32
+
33
+ rotated_image = cv2.warpAffine(image, M, (w, h))
34
+
35
+ return rotated_image
36
+
37
+ # Function to increase the brightness of an image
38
+ def increase_brightness(image, factor=1.2):
39
+ image = np.array(image, dtype=np.float32)
40
+
41
+ brightened_image = cv2.multiply(image, np.array([factor, factor, factor], dtype=np.float32))
42
+
43
+ brightened_image = np.clip(brightened_image, 0, 255).astype(np.uint8)
44
+
45
+ return brightened_image
46
+
src/utils/logger.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+
3
+ logging.basicConfig(
4
+ level=logging.INFO,
5
+ format='%(asctime)s - %(levelname)s - %(message)s',
6
+ datefmt='%Y-%m-%d %H:%M')
7
+
8
+ def log(log_type,message):
9
+ try:
10
+ log_type = log_type.lower()
11
+ if log_type == "info":
12
+ return logging.info(message)
13
+ elif log_type == "debug":
14
+ return logging.debug(message)
15
+ elif log_type == "warning":
16
+ return logging.error(message)
17
+ elif log_type == "critical":
18
+ return logging.critical(message)
19
+ elif log_type == "error":
20
+ return logging.error(message)
21
+ except Exception as e:
22
+ return f"Invalid log type.Error : {e}"