Upload folder using huggingface_hub
Browse files- .gitignore +3 -0
- .idea/.gitignore +3 -0
- .idea/Oxygen Level Intensity Mapper.iml +12 -0
- .idea/inspectionProfiles/Project_Default.xml +27 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- .idea/workspace.xml +110 -0
- Heatmap_Images/D1 AH 24 2_heatmap.jpg +0 -0
- Heatmap_Images/Image_01_heatmap.jpg +0 -0
- Heatmap_Images/Image_4180_heatmap.jpg +0 -0
- Heatmap_Images/Image_4185_heatmap.jpg +0 -0
- Heatmap_Images/heatmap_7d9bd02e-d124-4364-a132-9b6b7e63067c.jpg +0 -0
- Heatmap_Images/heatmap_90bbc842-671a-4231-99c5-fad12a6426a8.jpg +0 -0
- Heatmap_Images/heatmap_98efe41e-60a6-41e0-b075-fd618e43770b.jpg +0 -0
- README.md +50 -7
- Raw_Images/D1 AH 24 2.jpg +0 -0
- Raw_Images/Image_01.jpg +0 -0
- Raw_Images/Image_4180.jpg +0 -0
- Raw_Images/Image_4185.jpg +0 -0
- Raw_Images/Image_4304.jpg +0 -0
- Raw_Images/Image_4337.jpg +0 -0
- __pycache__/main.cpython-310.pyc +0 -0
- app.py +15 -0
- main.py +117 -0
- requirements.txt +4 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Gradio_Images
|
2 |
+
flagged
|
3 |
+
|
.idea/.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
.idea/Oxygen Level Intensity Mapper.iml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$" />
|
5 |
+
<orderEntry type="jdk" jdkName="teleplant" jdkType="Python SDK" />
|
6 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
7 |
+
</component>
|
8 |
+
<component name="PyDocumentationSettings">
|
9 |
+
<option name="format" value="PLAIN" />
|
10 |
+
<option name="myDocStringFormat" value="Plain" />
|
11 |
+
</component>
|
12 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
5 |
+
<option name="ignoredPackages">
|
6 |
+
<value>
|
7 |
+
<list size="14">
|
8 |
+
<item index="0" class="java.lang.String" itemvalue="scipy" />
|
9 |
+
<item index="1" class="java.lang.String" itemvalue="protobuf" />
|
10 |
+
<item index="2" class="java.lang.String" itemvalue="thop" />
|
11 |
+
<item index="3" class="java.lang.String" itemvalue="opencv-python" />
|
12 |
+
<item index="4" class="java.lang.String" itemvalue="PyYAML" />
|
13 |
+
<item index="5" class="java.lang.String" itemvalue="ipython" />
|
14 |
+
<item index="6" class="java.lang.String" itemvalue="numpy" />
|
15 |
+
<item index="7" class="java.lang.String" itemvalue="requests" />
|
16 |
+
<item index="8" class="java.lang.String" itemvalue="psutil" />
|
17 |
+
<item index="9" class="java.lang.String" itemvalue="tqdm" />
|
18 |
+
<item index="10" class="java.lang.String" itemvalue="pandas" />
|
19 |
+
<item index="11" class="java.lang.String" itemvalue="tensorboard" />
|
20 |
+
<item index="12" class="java.lang.String" itemvalue="seaborn" />
|
21 |
+
<item index="13" class="java.lang.String" itemvalue="matplotlib" />
|
22 |
+
</list>
|
23 |
+
</value>
|
24 |
+
</option>
|
25 |
+
</inspection_tool>
|
26 |
+
</profile>
|
27 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="Black">
|
4 |
+
<option name="sdkName" value="teleplant" />
|
5 |
+
</component>
|
6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="teleplant" project-jdk-type="Python SDK" />
|
7 |
+
</project>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/Oxygen Level Intensity Mapper.iml" filepath="$PROJECT_DIR$/.idea/Oxygen Level Intensity Mapper.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
.idea/workspace.xml
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="AutoImportSettings">
|
4 |
+
<option name="autoReloadType" value="SELECTIVE" />
|
5 |
+
</component>
|
6 |
+
<component name="ChangeListManager">
|
7 |
+
<list default="true" id="2d98c80b-c1bc-4875-942c-d13799747515" name="Changes" comment="" />
|
8 |
+
<option name="SHOW_DIALOG" value="false" />
|
9 |
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
10 |
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
11 |
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
12 |
+
</component>
|
13 |
+
<component name="FileTemplateManagerImpl">
|
14 |
+
<option name="RECENT_TEMPLATES">
|
15 |
+
<list>
|
16 |
+
<option value="Python Script" />
|
17 |
+
</list>
|
18 |
+
</option>
|
19 |
+
</component>
|
20 |
+
<component name="Git.Settings">
|
21 |
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
22 |
+
</component>
|
23 |
+
<component name="ProjectColorInfo"><![CDATA[{
|
24 |
+
"associatedIndex": 8
|
25 |
+
}]]></component>
|
26 |
+
<component name="ProjectId" id="2iAkUe6fUvTFkpeqnkXGlbeGHqK" />
|
27 |
+
<component name="ProjectViewState">
|
28 |
+
<option name="hideEmptyMiddlePackages" value="true" />
|
29 |
+
<option name="showLibraryContents" value="true" />
|
30 |
+
</component>
|
31 |
+
<component name="PropertiesComponent"><![CDATA[{
|
32 |
+
"keyToString": {
|
33 |
+
"Python.app.executor": "Run",
|
34 |
+
"Python.main.executor": "Run",
|
35 |
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
36 |
+
"git-widget-placeholder": "master",
|
37 |
+
"last_opened_file_path": "/home/ubuntu/Documents/Fold1/Oxygen Level Intensity Mapper"
|
38 |
+
}
|
39 |
+
}]]></component>
|
40 |
+
<component name="RunManager" selected="Python.app">
|
41 |
+
<configuration name="app" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
42 |
+
<module name="Oxygen Level Intensity Mapper" />
|
43 |
+
<option name="ENV_FILES" value="" />
|
44 |
+
<option name="INTERPRETER_OPTIONS" value="" />
|
45 |
+
<option name="PARENT_ENVS" value="true" />
|
46 |
+
<envs>
|
47 |
+
<env name="PYTHONUNBUFFERED" value="1" />
|
48 |
+
</envs>
|
49 |
+
<option name="SDK_HOME" value="" />
|
50 |
+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
51 |
+
<option name="IS_MODULE_SDK" value="true" />
|
52 |
+
<option name="ADD_CONTENT_ROOTS" value="true" />
|
53 |
+
<option name="ADD_SOURCE_ROOTS" value="true" />
|
54 |
+
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/app.py" />
|
55 |
+
<option name="PARAMETERS" value="" />
|
56 |
+
<option name="SHOW_COMMAND_LINE" value="false" />
|
57 |
+
<option name="EMULATE_TERMINAL" value="false" />
|
58 |
+
<option name="MODULE_MODE" value="false" />
|
59 |
+
<option name="REDIRECT_INPUT" value="false" />
|
60 |
+
<option name="INPUT_FILE" value="" />
|
61 |
+
<method v="2" />
|
62 |
+
</configuration>
|
63 |
+
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
64 |
+
<module name="Oxygen Level Intensity Mapper" />
|
65 |
+
<option name="ENV_FILES" value="" />
|
66 |
+
<option name="INTERPRETER_OPTIONS" value="" />
|
67 |
+
<option name="PARENT_ENVS" value="true" />
|
68 |
+
<envs>
|
69 |
+
<env name="PYTHONUNBUFFERED" value="1" />
|
70 |
+
</envs>
|
71 |
+
<option name="SDK_HOME" value="" />
|
72 |
+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
73 |
+
<option name="IS_MODULE_SDK" value="true" />
|
74 |
+
<option name="ADD_CONTENT_ROOTS" value="true" />
|
75 |
+
<option name="ADD_SOURCE_ROOTS" value="true" />
|
76 |
+
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
|
77 |
+
<option name="PARAMETERS" value="" />
|
78 |
+
<option name="SHOW_COMMAND_LINE" value="false" />
|
79 |
+
<option name="EMULATE_TERMINAL" value="false" />
|
80 |
+
<option name="MODULE_MODE" value="false" />
|
81 |
+
<option name="REDIRECT_INPUT" value="false" />
|
82 |
+
<option name="INPUT_FILE" value="" />
|
83 |
+
<method v="2" />
|
84 |
+
</configuration>
|
85 |
+
<recent_temporary>
|
86 |
+
<list>
|
87 |
+
<item itemvalue="Python.app" />
|
88 |
+
<item itemvalue="Python.main" />
|
89 |
+
</list>
|
90 |
+
</recent_temporary>
|
91 |
+
</component>
|
92 |
+
<component name="SharedIndexes">
|
93 |
+
<attachedChunks>
|
94 |
+
<set>
|
95 |
+
<option value="bundled-python-sdk-5b207ade9991-746f403e7f0c-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-241.17890.14" />
|
96 |
+
</set>
|
97 |
+
</attachedChunks>
|
98 |
+
</component>
|
99 |
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
100 |
+
<component name="TaskManager">
|
101 |
+
<task active="true" id="Default" summary="Default task">
|
102 |
+
<changelist id="2d98c80b-c1bc-4875-942c-d13799747515" name="Changes" comment="" />
|
103 |
+
<created>1718940786006</created>
|
104 |
+
<option name="number" value="Default" />
|
105 |
+
<option name="presentableId" value="Default" />
|
106 |
+
<updated>1718940786006</updated>
|
107 |
+
</task>
|
108 |
+
<servers />
|
109 |
+
</component>
|
110 |
+
</project>
|
Heatmap_Images/D1 AH 24 2_heatmap.jpg
ADDED
Heatmap_Images/Image_01_heatmap.jpg
ADDED
Heatmap_Images/Image_4180_heatmap.jpg
ADDED
Heatmap_Images/Image_4185_heatmap.jpg
ADDED
Heatmap_Images/heatmap_7d9bd02e-d124-4364-a132-9b6b7e63067c.jpg
ADDED
Heatmap_Images/heatmap_90bbc842-671a-4231-99c5-fad12a6426a8.jpg
ADDED
Heatmap_Images/heatmap_98efe41e-60a6-41e0-b075-fd618e43770b.jpg
ADDED
README.md
CHANGED
@@ -1,12 +1,55 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: blue
|
5 |
-
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.36.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
1 |
---
|
2 |
+
title: oxygen_level_intensity_mapper
|
3 |
+
app_file: app.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 4.36.1
|
|
|
|
|
6 |
---
|
7 |
+
# Oxygen Level Heatmap Generator
|
8 |
+
|
9 |
+
This Python script processes an image to generate a heatmap representing oxygen levels based on the intensity of the image. The image is divided into a 32x32 grid, and the intensity of each grid cell is calculated, normalized, and mapped to oxygen levels using a provided mapping table.
|
10 |
+
|
11 |
+
## Features
|
12 |
+
|
13 |
+
- Divide an image into a 32x32 grid.
|
14 |
+
- Calculate the intensity of each grid cell.
|
15 |
+
- Normalize the intensity values.
|
16 |
+
- Map the normalized intensities to oxygen levels based on a provided table.
|
17 |
+
- Generate and save a heatmap showing the oxygen levels.
|
18 |
+
|
19 |
+
## Requirements
|
20 |
+
|
21 |
+
- Python 3.x
|
22 |
+
- NumPy
|
23 |
+
- Pillow
|
24 |
+
- Matplotlib
|
25 |
+
- SciPy
|
26 |
+
|
27 |
+
## Installation
|
28 |
+
|
29 |
+
You can install the required Python libraries using `pip`:
|
30 |
+
|
31 |
+
```bash
|
32 |
+
pip install -r requirements.txt
|
33 |
+
```
|
34 |
+
|
35 |
+
## Usage
|
36 |
+
|
37 |
+
1. **Prepare the image:**
|
38 |
+
Place your image file in the `Raw_Images` directory or any directory of your choice.
|
39 |
+
|
40 |
+
2. **Run the script:**
|
41 |
+
Update the `image_path` variable in the script to point to your image file and run the script.
|
42 |
+
|
43 |
+
3. **Output:**
|
44 |
+
The generated heatmap will be saved in the `Heatmap_Images` directory with the filename `{image_name}_heatmap.jpg`.
|
45 |
+
|
46 |
+
|
47 |
+
## Run Script
|
48 |
+
|
49 |
+
To run the script you can just run following command in terminal;
|
50 |
+
|
51 |
+
```python
|
52 |
+
python main.py
|
53 |
+
```
|
54 |
|
55 |
+
Make sure the current working directory shall be the Folder named 'Oxygen-Level-Intensity-Mapper/'
|
Raw_Images/D1 AH 24 2.jpg
ADDED
Raw_Images/Image_01.jpg
ADDED
Raw_Images/Image_4180.jpg
ADDED
Raw_Images/Image_4185.jpg
ADDED
Raw_Images/Image_4304.jpg
ADDED
Raw_Images/Image_4337.jpg
ADDED
__pycache__/main.cpython-310.pyc
ADDED
Binary file (3.03 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from main import process_and_generate_heatmap
|
4 |
+
|
5 |
+
if __name__ == "__main__":
|
6 |
+
iface = gr.Interface(
|
7 |
+
fn=process_and_generate_heatmap,
|
8 |
+
inputs=gr.Image(type="pil"),
|
9 |
+
outputs=gr.File(label="Heatmap Image"),
|
10 |
+
title="Heatmap Generator",
|
11 |
+
description="Upload an image to generate a high-resolution heatmap."
|
12 |
+
)
|
13 |
+
|
14 |
+
# Launch the app
|
15 |
+
iface.launch(share=True)
|
main.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from PIL import Image
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import matplotlib.colors as mcolors
|
5 |
+
from scipy.interpolate import interp1d
|
6 |
+
import os
|
7 |
+
import uuid
|
8 |
+
|
9 |
+
|
10 |
+
def calculate_intensity(image):
|
11 |
+
"""
|
12 |
+
Calculate the intensity of the image by converting it to grayscale
|
13 |
+
and taking the mean value.
|
14 |
+
"""
|
15 |
+
gray_image = image.convert('L') # Convert to grayscale
|
16 |
+
intensity = np.mean(np.array(gray_image))
|
17 |
+
return intensity
|
18 |
+
|
19 |
+
|
20 |
+
def process_image(image_path):
|
21 |
+
"""
|
22 |
+
Process the image by dividing it into 32x32 grids and calculating normalized intensity.
|
23 |
+
"""
|
24 |
+
# Open the image
|
25 |
+
image = Image.open(image_path)
|
26 |
+
width, height = image.size
|
27 |
+
|
28 |
+
# Determine the ideal grid size
|
29 |
+
grid_width = width // 32
|
30 |
+
grid_height = height // 32
|
31 |
+
|
32 |
+
intensities = []
|
33 |
+
|
34 |
+
# Divide the image into grids and calculate intensity for each grid
|
35 |
+
for y in range(32):
|
36 |
+
row_intensities = []
|
37 |
+
for x in range(32):
|
38 |
+
left = x * grid_width
|
39 |
+
upper = y * grid_height
|
40 |
+
right = left + grid_width
|
41 |
+
lower = upper + grid_height
|
42 |
+
|
43 |
+
# Crop the image to the grid
|
44 |
+
grid = image.crop((left, upper, right, lower))
|
45 |
+
intensity = calculate_intensity(grid)
|
46 |
+
row_intensities.append(intensity)
|
47 |
+
intensities.append(row_intensities)
|
48 |
+
|
49 |
+
intensities = np.array(intensities)
|
50 |
+
|
51 |
+
# Normalize the intensities to the range 0-1
|
52 |
+
min_intensity = intensities.min()
|
53 |
+
max_intensity = intensities.max()
|
54 |
+
normalized_intensities = (intensities - min_intensity) / (max_intensity - min_intensity)
|
55 |
+
|
56 |
+
return normalized_intensities
|
57 |
+
|
58 |
+
|
59 |
+
def intensity_to_oxygen_level(normalized_intensities):
|
60 |
+
"""
|
61 |
+
Map normalized intensity values to oxygen levels using interpolation.
|
62 |
+
"""
|
63 |
+
# Provided mapping table
|
64 |
+
ksv_values = [0, 0.009303080328, 0.19176, 0.5196879311, 0.6252571452, 0.7115134738,
|
65 |
+
0.8476158622, 0.9531850764, 1.039441405, 1.145010619, 1.175543793,
|
66 |
+
1.231266948, 1.281113007, 1.47293855, 1.609040939]
|
67 |
+
oxygen_levels = [0, 0.68, 1, 2, 2.5, 3, 4, 5, 6, 7.5, 8, 9, 10, 15, 20]
|
68 |
+
|
69 |
+
# Normalize intensities to match the range of Ksv values
|
70 |
+
min_ksv = min(ksv_values)
|
71 |
+
max_ksv = max(ksv_values)
|
72 |
+
normalized_intensities = (normalized_intensities * (max_ksv - min_ksv)) + min_ksv
|
73 |
+
|
74 |
+
# Interpolation function
|
75 |
+
interp_func = interp1d(ksv_values, oxygen_levels, kind='linear', fill_value='extrapolate')
|
76 |
+
oxygen_levels_mapped = interp_func(normalized_intensities)
|
77 |
+
|
78 |
+
return oxygen_levels_mapped
|
79 |
+
|
80 |
+
|
81 |
+
def generate_heatmap(data, output_path):
|
82 |
+
"""
|
83 |
+
Generate a high-resolution heatmap from data and save it as an image.
|
84 |
+
"""
|
85 |
+
plt.figure(figsize=(10, 8))
|
86 |
+
plt.imshow(data, cmap='RdBu_r', interpolation='nearest', norm=mcolors.Normalize(vmin=0, vmax=20))
|
87 |
+
plt.colorbar(label='Oxygen Level (%)')
|
88 |
+
|
89 |
+
# Save the figure with high resolution
|
90 |
+
plt.savefig(output_path, dpi=300)
|
91 |
+
plt.close()
|
92 |
+
|
93 |
+
|
94 |
+
def process_and_generate_heatmap(image):
|
95 |
+
"""
|
96 |
+
Process the image and generate a heatmap, saving the result to a file.
|
97 |
+
"""
|
98 |
+
# Generate a unique name for the input image
|
99 |
+
unique_id = str(uuid.uuid4())
|
100 |
+
input_dir = 'Gradio_Images'
|
101 |
+
input_image_path = os.path.join(input_dir, f'uploaded_image_{unique_id}.jpg')
|
102 |
+
image.save(input_image_path)
|
103 |
+
|
104 |
+
# Process the image to get normalized intensities
|
105 |
+
normalized_intensities = process_image(input_image_path)
|
106 |
+
oxygen_levels = intensity_to_oxygen_level(normalized_intensities)
|
107 |
+
|
108 |
+
# Generate the output path for the heatmap based on the unique name
|
109 |
+
output_dir = 'Heatmap_Images'
|
110 |
+
|
111 |
+
output_image_path = os.path.join(output_dir, f'heatmap_{unique_id}.jpg')
|
112 |
+
|
113 |
+
generate_heatmap(oxygen_levels, output_image_path)
|
114 |
+
|
115 |
+
return output_image_path
|
116 |
+
|
117 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
matplotlib==3.8.4
|
2 |
+
numpy==1.26.4
|
3 |
+
Pillow==10.0.1
|
4 |
+
scipy==1.13.1
|