AmrGharieb commited on
Commit
48caa33
1 Parent(s): 7d386ab

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirements.txt +91 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import cv2
4
+ import numpy as np
5
+ import gradio as gr
6
+ from PIL import Image as PILImage
7
+
8
+ def threshold_segmentation_gradio(image, threshold_value):
9
+ """
10
+ Applies threshold segmentation and displays results in a Gradio interface.
11
+
12
+ Args:
13
+ image_path: Path to the image file.
14
+ threshold_value: Threshold value for binarization.
15
+
16
+ Returns:
17
+ A tuple of:
18
+ - Thresholded image: Gradio Image component.
19
+ - Bright pixel count: Gradio Label component.
20
+ - Dim pixel count: Gradio Label component.
21
+ - Total pixel count: Gradio Label component.
22
+ """
23
+ # Convert PIL image to grayscale OpenCV format (assuming RGB format)
24
+ image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
25
+
26
+ # Apply thresholding
27
+ _, thresholded_image = cv2.threshold(image, threshold_value, 255, cv2.THRESH_BINARY)
28
+
29
+ # Count bright and dim pixels
30
+ bright_count = cv2.countNonZero(thresholded_image)
31
+ dim_count = thresholded_image.size - bright_count
32
+ total_count = thresholded_image.size
33
+
34
+ return thresholded_image,bright_count, dim_count, total_count
35
+
36
+
37
+
38
+ if __name__ == "__main__":
39
+ # Launch the Gradio interface
40
+ inputs = [gr.Image(type="pil"), gr.Slider(0, 255)]
41
+ outputs = [gr.Image(label="Thresholded Image"),gr.Label(label="Bright Pixels"), gr.Label(label="Dim Pixels"), gr.Label(label="Total Pixels")]
42
+
43
+ # Launch the Gradio interface
44
+ interface = gr.Interface(fn=threshold_segmentation_gradio, inputs=inputs, outputs=outputs,css="footer { visibility: hidden }")
45
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ altair==5.2.0
3
+ annotated-types==0.6.0
4
+ anyio==3.7.1
5
+ asttokens==2.4.1
6
+ attrs==23.1.0
7
+ certifi==2023.11.17
8
+ charset-normalizer==3.3.2
9
+ click==8.1.7
10
+ colorama==0.4.6
11
+ comm==0.2.0
12
+ contourpy==1.2.0
13
+ cycler==0.12.1
14
+ debugpy==1.8.0
15
+ decorator==5.1.1
16
+ exceptiongroup==1.2.0
17
+ executing==2.0.1
18
+ fastapi==0.104.1
19
+ ffmpy==0.3.1
20
+ filelock==3.13.1
21
+ fonttools==4.45.1
22
+ fsspec==2023.10.0
23
+ gradio==4.7.1
24
+ gradio_client==0.7.0
25
+ h11==0.14.0
26
+ httpcore==1.0.2
27
+ httpx==0.25.2
28
+ huggingface-hub==0.19.4
29
+ idna==3.6
30
+ importlib-metadata==6.8.0
31
+ importlib-resources==6.1.1
32
+ ipykernel==6.27.1
33
+ ipython==8.18.1
34
+ jedi==0.19.1
35
+ Jinja2==3.1.2
36
+ jsonschema==4.20.0
37
+ jsonschema-specifications==2023.11.2
38
+ jupyter_client==8.6.0
39
+ jupyter_core==5.5.0
40
+ kiwisolver==1.4.5
41
+ markdown-it-py==3.0.0
42
+ MarkupSafe==2.1.3
43
+ matplotlib==3.8.2
44
+ matplotlib-inline==0.1.6
45
+ mdurl==0.1.2
46
+ nest-asyncio==1.5.8
47
+ numpy==1.26.2
48
+ opencv-python==4.8.1.78
49
+ orjson==3.9.10
50
+ packaging==23.2
51
+ pandas==2.1.3
52
+ parso==0.8.3
53
+ Pillow==10.1.0
54
+ platformdirs==4.0.0
55
+ prompt-toolkit==3.0.41
56
+ psutil==5.9.6
57
+ pure-eval==0.2.2
58
+ pydantic==2.5.2
59
+ pydantic_core==2.14.5
60
+ pydub==0.25.1
61
+ Pygments==2.17.2
62
+ pyparsing==3.1.1
63
+ python-dateutil==2.8.2
64
+ python-multipart==0.0.6
65
+ pytz==2023.3.post1
66
+ pywin32==306
67
+ PyYAML==6.0.1
68
+ pyzmq==25.1.1
69
+ referencing==0.31.1
70
+ requests==2.31.0
71
+ rich==13.7.0
72
+ rpds-py==0.13.2
73
+ semantic-version==2.10.0
74
+ shellingham==1.5.4
75
+ six==1.16.0
76
+ sniffio==1.3.0
77
+ stack-data==0.6.3
78
+ starlette==0.27.0
79
+ tomlkit==0.12.0
80
+ toolz==0.12.0
81
+ tornado==6.4
82
+ tqdm==4.66.1
83
+ traitlets==5.14.0
84
+ typer==0.9.0
85
+ typing_extensions==4.8.0
86
+ tzdata==2023.3
87
+ urllib3==2.1.0
88
+ uvicorn==0.24.0.post1
89
+ wcwidth==0.2.12
90
+ websockets==11.0.3
91
+ zipp==3.17.0