Skip to content

Commit 2c29734

Browse files
committed
Added ability to process 'tif' and 'tiff' images. Work of gr.Examples is extended to gr.ImageEditor. Work of introjs is fixed.
1 parent 38d1713 commit 2c29734

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

particleanalyzer/core/ui.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,21 @@ def create_interface(api_key):
138138
elem_classes="styled-dropdown",
139139
)
140140
with gr.Row() as row_image_file:
141-
image_file = gr.File(label=i18n("Загрузить изображение СЭМ"), file_types=[".tif", ".tiff", ".png", ".jpg", ".jpeg", ".bmp", ".webp"], file_count="single", elem_id="image-file",)
141+
image_file = gr.File(
142+
label=i18n("Загрузить изображение СЭМ"),
143+
file_types=[
144+
".tif",
145+
".tiff",
146+
".png",
147+
".jpg",
148+
".jpeg",
149+
".bmp",
150+
".webp",
151+
],
152+
file_count="single",
153+
elem_id="image-file",
154+
height=450,
155+
)
142156
with gr.Row(visible=False) as row_analysis:
143157
with gr.Column():
144158
with gr.Row(
@@ -195,7 +209,8 @@ def create_interface(api_key):
195209
show_copy_button=True,
196210
)
197211
with gr.Row(
198-
visible=False, elem_id="reset-delete-buttons-row"
212+
visible=False,
213+
elem_id="reset-delete-buttons-row",
199214
) as reset_delete_buttons_row:
200215
with gr.Column():
201216
reset_df = gr.Button(
@@ -235,14 +250,14 @@ def create_interface(api_key):
235250
elem_classes="custom-btn btn-clear",
236251
)
237252

238-
with gr.Row(elem_id="example-row") as in_image_example_row:
253+
with gr.Row(elem_id="example-row"):
239254
gr.Examples(
240255
examples=[
241-
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/main/example/100%20r-.jpg",
242-
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/main/example/Tv30_1.webp",
243-
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/main/example/A02-1.webp",
244-
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/main/example/Resolution%20in%20SEM%201.jpg",
245-
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/main/example/image_c_01.webp",
256+
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/refs/heads/main/example/Cathode_LiCoVO4.jpg",
257+
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/refs/heads/main/example/Chitosan.webp",
258+
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/refs/heads/main/example/Silicon_oxide.webp",
259+
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/refs/heads/main/example/Gold_on_carbon.jpg",
260+
"https://raw.githubusercontent.com/rybakov-ks/ParticleAnalyzer/refs/heads/main/example/Colloidal_silver.webp",
246261
],
247262
inputs=[image_file],
248263
label=i18n("Примеры"),
@@ -541,7 +556,11 @@ def create_interface(api_key):
541556
# </button>
542557
# """
543558
# )
544-
image_file.change(fn=handle_file_upload, inputs=[image_file, scale_selector], outputs=[in_image, im, row_image_file, row_analysis])
559+
image_file.change(
560+
fn=handle_file_upload,
561+
inputs=[image_file, scale_selector],
562+
outputs=[in_image, im, row_image_file, row_analysis],
563+
)
545564
analyze = process_button.click(
546565
fn=analyzer.analyze_image,
547566
inputs=[
@@ -626,7 +645,7 @@ def create_interface(api_key):
626645
I_slider,
627646
],
628647
show_progress="hide",
629-
show_progress_on=[points_df]
648+
show_progress_on=[points_df],
630649
).success(
631650
fn=statistic_an,
632651
inputs=[

particleanalyzer/core/utils.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from PIL import Image
66
import csv
77
import os
8-
from pathlib import Path
98
from datetime import datetime
109
from particleanalyzer.core.languages import translations
1110
from particleanalyzer.core.language_context import LanguageContext
@@ -127,7 +126,7 @@ def reset_interface(scale_value):
127126
[(None, None)], # Очищаем chatbot
128127
gr.update(visible=False), # Скрываем строку results_row
129128
gr.update(visible=False), # Скрываем sidebar
130-
gr.update(visible=True), # Показываем строку row_image_file
129+
gr.update(visible=True), # Показываем строку row_image_file
131130
gr.update(visible=False), # Скрываем строку row_analysis
132131
None, # Очищаем image_file
133132
)
@@ -333,7 +332,11 @@ def statistic_an(
333332
)
334333
selected_image = cv2.cvtColor(selected_image, cv2.COLOR_BGR2RGB)
335334

336-
return selected_image, stats_df, fig,
335+
return (
336+
selected_image,
337+
stats_df,
338+
fig,
339+
)
337340

338341

339342
selected_particles = [] # Глобальный список для хранения выбранных частиц
@@ -395,7 +398,9 @@ def reset_selection(output_table_image2):
395398
)
396399

397400

398-
def particle_removal(output_table_image2, points_df, output_table, round_value, scale_selector):
401+
def particle_removal(
402+
output_table_image2, points_df, output_table, round_value, scale_selector
403+
):
399404
global selected_particles
400405
if not output_table_image2.empty and "№" in output_table_image2.columns:
401406
try:
@@ -415,9 +420,9 @@ def particle_removal(output_table_image2, points_df, output_table, round_value,
415420
limits = ParticleAnalyzer.calculate_limits(output_table, round_value)
416421
scale_selector = ParticleAnalyzer.SCALE_OPTIONS[scale_selector]
417422
return (
418-
gr.update(visible=False),
419-
gr.update(visible=False),
420-
points_df,
423+
gr.update(visible=False),
424+
gr.update(visible=False),
425+
points_df,
421426
output_table,
422427
gr.update(
423428
minimum=limits["d_max_min"],
@@ -428,9 +433,9 @@ def particle_removal(output_table_image2, points_df, output_table, round_value,
428433
),
429434
gr.update(
430435
minimum=limits["d_min_min"],
431-
maximum=limits["d_min_max"] ,
432-
value=(limits["d_min_min"], limits["d_min_max"] ),
433-
step=limits["d_min_max"] * 0.01,
436+
maximum=limits["d_min_max"],
437+
value=(limits["d_min_min"], limits["d_min_max"]),
438+
step=limits["d_min_max"] * 0.01,
434439
label=f"Dₘᵢₙ [{get_translation(scale_selector['unit'])}]",
435440
),
436441
gr.update(
@@ -458,9 +463,14 @@ def particle_removal(output_table_image2, points_df, output_table, round_value,
458463
step=limits["P_max"] * 0.01,
459464
label=f"P [{get_translation(scale_selector['unit'])}]",
460465
),
461-
gr.update(minimum=limits["I_min"], maximum=limits["I_max"], value=(limits["I_min"], limits["I_max"])),
466+
gr.update(
467+
minimum=limits["I_min"],
468+
maximum=limits["I_max"],
469+
value=(limits["I_min"], limits["I_max"]),
470+
),
462471
)
463472

473+
464474
def img_to_numpy_array(file_path):
465475
try:
466476
with Image.open(file_path) as img:
@@ -469,15 +479,13 @@ def img_to_numpy_array(file_path):
469479
except Exception as e:
470480
print(f"Ошибка при загрузке TIFF: {e}")
471481
return None, None
472-
482+
483+
473484
def handle_file_upload(file, scale_selector):
474485
if file is None:
475486
return gr.skip(), gr.skip(), gr.update(visible=True), gr.update(visible=False)
476-
477-
scale = ParticleAnalyzer.SCALE_OPTIONS[scale_selector]["scale"]
478-
487+
479488
file_path = file.name
480-
file_ext = Path(file_path).suffix.lower()[1:]
481489
in_image, im = img_to_numpy_array(file_path)
482490

483491
return (
@@ -487,6 +495,7 @@ def handle_file_upload(file, scale_selector):
487495
gr.update(visible=True),
488496
)
489497

498+
490499
empty_df_ParticleCharacteristics = get_columns("Pixels").fillna("")
491500
empty_df_ParticleStatistics = get_stats_columns()
492501

particleanalyzer/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.38"
1+
__version__ = "1.0.0"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def read_file(filename):
99

1010
setup(
1111
name="ParticleAnalyzer",
12-
version="0.1.38",
12+
version="1.0.0",
1313
packages=find_packages(exclude=["tests*"]),
1414
package_data={
1515
"particleanalyzer": [

0 commit comments

Comments
 (0)