setiastrosuitepro 1.6.5.post3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- setiastro/__init__.py +2 -0
- setiastro/data/SASP_data.fits +0 -0
- setiastro/data/catalogs/List_of_Galaxies_with_Distances_Gly.csv +488 -0
- setiastro/data/catalogs/astrobin_filters.csv +890 -0
- setiastro/data/catalogs/astrobin_filters_page1_local.csv +51 -0
- setiastro/data/catalogs/cali2.csv +63 -0
- setiastro/data/catalogs/cali2color.csv +65 -0
- setiastro/data/catalogs/celestial_catalog - original.csv +16471 -0
- setiastro/data/catalogs/celestial_catalog.csv +24031 -0
- setiastro/data/catalogs/detected_stars.csv +24784 -0
- setiastro/data/catalogs/fits_header_data.csv +46 -0
- setiastro/data/catalogs/test.csv +8 -0
- setiastro/data/catalogs/updated_celestial_catalog.csv +16471 -0
- setiastro/images/Astro_Spikes.png +0 -0
- setiastro/images/Background_startup.jpg +0 -0
- setiastro/images/HRDiagram.png +0 -0
- setiastro/images/LExtract.png +0 -0
- setiastro/images/LInsert.png +0 -0
- setiastro/images/Oxygenation-atm-2.svg.png +0 -0
- setiastro/images/RGB080604.png +0 -0
- setiastro/images/abeicon.png +0 -0
- setiastro/images/aberration.png +0 -0
- setiastro/images/andromedatry.png +0 -0
- setiastro/images/andromedatry_satellited.png +0 -0
- setiastro/images/annotated.png +0 -0
- setiastro/images/aperture.png +0 -0
- setiastro/images/astrosuite.ico +0 -0
- setiastro/images/astrosuite.png +0 -0
- setiastro/images/astrosuitepro.icns +0 -0
- setiastro/images/astrosuitepro.ico +0 -0
- setiastro/images/astrosuitepro.png +0 -0
- setiastro/images/background.png +0 -0
- setiastro/images/background2.png +0 -0
- setiastro/images/benchmark.png +0 -0
- setiastro/images/big_moon_stabilizer_timeline.png +0 -0
- setiastro/images/big_moon_stabilizer_timeline_clean.png +0 -0
- setiastro/images/blaster.png +0 -0
- setiastro/images/blink.png +0 -0
- setiastro/images/clahe.png +0 -0
- setiastro/images/collage.png +0 -0
- setiastro/images/colorwheel.png +0 -0
- setiastro/images/contsub.png +0 -0
- setiastro/images/convo.png +0 -0
- setiastro/images/copyslot.png +0 -0
- setiastro/images/cosmic.png +0 -0
- setiastro/images/cosmicsat.png +0 -0
- setiastro/images/crop1.png +0 -0
- setiastro/images/cropicon.png +0 -0
- setiastro/images/curves.png +0 -0
- setiastro/images/cvs.png +0 -0
- setiastro/images/debayer.png +0 -0
- setiastro/images/denoise_cnn_custom.png +0 -0
- setiastro/images/denoise_cnn_graph.png +0 -0
- setiastro/images/disk.png +0 -0
- setiastro/images/dse.png +0 -0
- setiastro/images/exoicon.png +0 -0
- setiastro/images/eye.png +0 -0
- setiastro/images/fliphorizontal.png +0 -0
- setiastro/images/flipvertical.png +0 -0
- setiastro/images/font.png +0 -0
- setiastro/images/freqsep.png +0 -0
- setiastro/images/functionbundle.png +0 -0
- setiastro/images/graxpert.png +0 -0
- setiastro/images/green.png +0 -0
- setiastro/images/gridicon.png +0 -0
- setiastro/images/halo.png +0 -0
- setiastro/images/hdr.png +0 -0
- setiastro/images/histogram.png +0 -0
- setiastro/images/hubble.png +0 -0
- setiastro/images/imagecombine.png +0 -0
- setiastro/images/invert.png +0 -0
- setiastro/images/isophote.png +0 -0
- setiastro/images/isophote_demo_figure.png +0 -0
- setiastro/images/isophote_demo_image.png +0 -0
- setiastro/images/isophote_demo_model.png +0 -0
- setiastro/images/isophote_demo_residual.png +0 -0
- setiastro/images/jwstpupil.png +0 -0
- setiastro/images/linearfit.png +0 -0
- setiastro/images/livestacking.png +0 -0
- setiastro/images/mask.png +0 -0
- setiastro/images/maskapply.png +0 -0
- setiastro/images/maskcreate.png +0 -0
- setiastro/images/maskremove.png +0 -0
- setiastro/images/morpho.png +0 -0
- setiastro/images/mosaic.png +0 -0
- setiastro/images/multiscale_decomp.png +0 -0
- setiastro/images/nbtorgb.png +0 -0
- setiastro/images/neutral.png +0 -0
- setiastro/images/nuke.png +0 -0
- setiastro/images/openfile.png +0 -0
- setiastro/images/pedestal.png +0 -0
- setiastro/images/pen.png +0 -0
- setiastro/images/pixelmath.png +0 -0
- setiastro/images/platesolve.png +0 -0
- setiastro/images/ppp.png +0 -0
- setiastro/images/pro.png +0 -0
- setiastro/images/project.png +0 -0
- setiastro/images/psf.png +0 -0
- setiastro/images/redo.png +0 -0
- setiastro/images/redoicon.png +0 -0
- setiastro/images/rescale.png +0 -0
- setiastro/images/rgbalign.png +0 -0
- setiastro/images/rgbcombo.png +0 -0
- setiastro/images/rgbextract.png +0 -0
- setiastro/images/rotate180.png +0 -0
- setiastro/images/rotatearbitrary.png +0 -0
- setiastro/images/rotateclockwise.png +0 -0
- setiastro/images/rotatecounterclockwise.png +0 -0
- setiastro/images/satellite.png +0 -0
- setiastro/images/script.png +0 -0
- setiastro/images/selectivecolor.png +0 -0
- setiastro/images/simbad.png +0 -0
- setiastro/images/slot0.png +0 -0
- setiastro/images/slot1.png +0 -0
- setiastro/images/slot2.png +0 -0
- setiastro/images/slot3.png +0 -0
- setiastro/images/slot4.png +0 -0
- setiastro/images/slot5.png +0 -0
- setiastro/images/slot6.png +0 -0
- setiastro/images/slot7.png +0 -0
- setiastro/images/slot8.png +0 -0
- setiastro/images/slot9.png +0 -0
- setiastro/images/spcc.png +0 -0
- setiastro/images/spin_precession_vs_lunar_distance.png +0 -0
- setiastro/images/spinner.gif +0 -0
- setiastro/images/stacking.png +0 -0
- setiastro/images/staradd.png +0 -0
- setiastro/images/staralign.png +0 -0
- setiastro/images/starnet.png +0 -0
- setiastro/images/starregistration.png +0 -0
- setiastro/images/starspike.png +0 -0
- setiastro/images/starstretch.png +0 -0
- setiastro/images/statstretch.png +0 -0
- setiastro/images/supernova.png +0 -0
- setiastro/images/uhs.png +0 -0
- setiastro/images/undoicon.png +0 -0
- setiastro/images/upscale.png +0 -0
- setiastro/images/viewbundle.png +0 -0
- setiastro/images/whitebalance.png +0 -0
- setiastro/images/wimi_icon_256x256.png +0 -0
- setiastro/images/wimilogo.png +0 -0
- setiastro/images/wims.png +0 -0
- setiastro/images/wrench_icon.png +0 -0
- setiastro/images/xisfliberator.png +0 -0
- setiastro/qml/ResourceMonitor.qml +126 -0
- setiastro/saspro/__init__.py +20 -0
- setiastro/saspro/__main__.py +958 -0
- setiastro/saspro/_generated/__init__.py +7 -0
- setiastro/saspro/_generated/build_info.py +3 -0
- setiastro/saspro/abe.py +1346 -0
- setiastro/saspro/abe_preset.py +196 -0
- setiastro/saspro/aberration_ai.py +698 -0
- setiastro/saspro/aberration_ai_preset.py +224 -0
- setiastro/saspro/accel_installer.py +218 -0
- setiastro/saspro/accel_workers.py +30 -0
- setiastro/saspro/add_stars.py +624 -0
- setiastro/saspro/astrobin_exporter.py +1010 -0
- setiastro/saspro/astrospike.py +153 -0
- setiastro/saspro/astrospike_python.py +1841 -0
- setiastro/saspro/autostretch.py +198 -0
- setiastro/saspro/backgroundneutral.py +611 -0
- setiastro/saspro/batch_convert.py +328 -0
- setiastro/saspro/batch_renamer.py +522 -0
- setiastro/saspro/blemish_blaster.py +491 -0
- setiastro/saspro/blink_comparator_pro.py +3149 -0
- setiastro/saspro/bundles.py +61 -0
- setiastro/saspro/bundles_dock.py +114 -0
- setiastro/saspro/cheat_sheet.py +213 -0
- setiastro/saspro/clahe.py +368 -0
- setiastro/saspro/comet_stacking.py +1442 -0
- setiastro/saspro/common_tr.py +107 -0
- setiastro/saspro/config.py +38 -0
- setiastro/saspro/config_bootstrap.py +40 -0
- setiastro/saspro/config_manager.py +316 -0
- setiastro/saspro/continuum_subtract.py +1617 -0
- setiastro/saspro/convo.py +1400 -0
- setiastro/saspro/convo_preset.py +414 -0
- setiastro/saspro/copyastro.py +190 -0
- setiastro/saspro/cosmicclarity.py +1589 -0
- setiastro/saspro/cosmicclarity_preset.py +407 -0
- setiastro/saspro/crop_dialog_pro.py +983 -0
- setiastro/saspro/crop_preset.py +189 -0
- setiastro/saspro/curve_editor_pro.py +2562 -0
- setiastro/saspro/curves_preset.py +375 -0
- setiastro/saspro/debayer.py +673 -0
- setiastro/saspro/debug_utils.py +29 -0
- setiastro/saspro/dnd_mime.py +35 -0
- setiastro/saspro/doc_manager.py +2664 -0
- setiastro/saspro/exoplanet_detector.py +2166 -0
- setiastro/saspro/file_utils.py +284 -0
- setiastro/saspro/fitsmodifier.py +748 -0
- setiastro/saspro/fix_bom.py +32 -0
- setiastro/saspro/free_torch_memory.py +48 -0
- setiastro/saspro/frequency_separation.py +1349 -0
- setiastro/saspro/function_bundle.py +1596 -0
- setiastro/saspro/generate_translations.py +3092 -0
- setiastro/saspro/ghs_dialog_pro.py +663 -0
- setiastro/saspro/ghs_preset.py +284 -0
- setiastro/saspro/graxpert.py +637 -0
- setiastro/saspro/graxpert_preset.py +287 -0
- setiastro/saspro/gui/__init__.py +0 -0
- setiastro/saspro/gui/main_window.py +8792 -0
- setiastro/saspro/gui/mixins/__init__.py +33 -0
- setiastro/saspro/gui/mixins/dock_mixin.py +375 -0
- setiastro/saspro/gui/mixins/file_mixin.py +450 -0
- setiastro/saspro/gui/mixins/geometry_mixin.py +503 -0
- setiastro/saspro/gui/mixins/header_mixin.py +441 -0
- setiastro/saspro/gui/mixins/mask_mixin.py +421 -0
- setiastro/saspro/gui/mixins/menu_mixin.py +390 -0
- setiastro/saspro/gui/mixins/theme_mixin.py +367 -0
- setiastro/saspro/gui/mixins/toolbar_mixin.py +1619 -0
- setiastro/saspro/gui/mixins/update_mixin.py +323 -0
- setiastro/saspro/gui/mixins/view_mixin.py +435 -0
- setiastro/saspro/gui/statistics_dialog.py +47 -0
- setiastro/saspro/halobgon.py +488 -0
- setiastro/saspro/header_viewer.py +448 -0
- setiastro/saspro/headless_utils.py +88 -0
- setiastro/saspro/histogram.py +756 -0
- setiastro/saspro/history_explorer.py +941 -0
- setiastro/saspro/i18n.py +168 -0
- setiastro/saspro/image_combine.py +417 -0
- setiastro/saspro/image_peeker_pro.py +1604 -0
- setiastro/saspro/imageops/__init__.py +37 -0
- setiastro/saspro/imageops/mdi_snap.py +292 -0
- setiastro/saspro/imageops/scnr.py +36 -0
- setiastro/saspro/imageops/starbasedwhitebalance.py +210 -0
- setiastro/saspro/imageops/stretch.py +236 -0
- setiastro/saspro/isophote.py +1182 -0
- setiastro/saspro/layers.py +208 -0
- setiastro/saspro/layers_dock.py +714 -0
- setiastro/saspro/lazy_imports.py +193 -0
- setiastro/saspro/legacy/__init__.py +2 -0
- setiastro/saspro/legacy/image_manager.py +2360 -0
- setiastro/saspro/legacy/numba_utils.py +3676 -0
- setiastro/saspro/legacy/xisf.py +1213 -0
- setiastro/saspro/linear_fit.py +537 -0
- setiastro/saspro/live_stacking.py +1854 -0
- setiastro/saspro/log_bus.py +5 -0
- setiastro/saspro/logging_config.py +460 -0
- setiastro/saspro/luminancerecombine.py +510 -0
- setiastro/saspro/main_helpers.py +201 -0
- setiastro/saspro/mask_creation.py +1086 -0
- setiastro/saspro/masks_core.py +56 -0
- setiastro/saspro/mdi_widgets.py +353 -0
- setiastro/saspro/memory_utils.py +666 -0
- setiastro/saspro/metadata_patcher.py +75 -0
- setiastro/saspro/mfdeconv.py +3909 -0
- setiastro/saspro/mfdeconv_earlystop.py +71 -0
- setiastro/saspro/mfdeconvcudnn.py +3312 -0
- setiastro/saspro/mfdeconvsport.py +2459 -0
- setiastro/saspro/minorbodycatalog.py +567 -0
- setiastro/saspro/morphology.py +407 -0
- setiastro/saspro/multiscale_decomp.py +1747 -0
- setiastro/saspro/nbtorgb_stars.py +541 -0
- setiastro/saspro/numba_utils.py +3145 -0
- setiastro/saspro/numba_warmup.py +141 -0
- setiastro/saspro/ops/__init__.py +9 -0
- setiastro/saspro/ops/command_help_dialog.py +623 -0
- setiastro/saspro/ops/command_runner.py +217 -0
- setiastro/saspro/ops/commands.py +1594 -0
- setiastro/saspro/ops/script_editor.py +1105 -0
- setiastro/saspro/ops/scripts.py +1476 -0
- setiastro/saspro/ops/settings.py +637 -0
- setiastro/saspro/parallel_utils.py +554 -0
- setiastro/saspro/pedestal.py +121 -0
- setiastro/saspro/perfect_palette_picker.py +1105 -0
- setiastro/saspro/pipeline.py +110 -0
- setiastro/saspro/pixelmath.py +1604 -0
- setiastro/saspro/plate_solver.py +2445 -0
- setiastro/saspro/project_io.py +797 -0
- setiastro/saspro/psf_utils.py +136 -0
- setiastro/saspro/psf_viewer.py +549 -0
- setiastro/saspro/pyi_rthook_astroquery.py +95 -0
- setiastro/saspro/remove_green.py +331 -0
- setiastro/saspro/remove_stars.py +1599 -0
- setiastro/saspro/remove_stars_preset.py +446 -0
- setiastro/saspro/resources.py +503 -0
- setiastro/saspro/rgb_combination.py +208 -0
- setiastro/saspro/rgb_extract.py +19 -0
- setiastro/saspro/rgbalign.py +723 -0
- setiastro/saspro/runtime_imports.py +7 -0
- setiastro/saspro/runtime_torch.py +754 -0
- setiastro/saspro/save_options.py +73 -0
- setiastro/saspro/selective_color.py +1611 -0
- setiastro/saspro/sfcc.py +1472 -0
- setiastro/saspro/shortcuts.py +3116 -0
- setiastro/saspro/signature_insert.py +1102 -0
- setiastro/saspro/stacking_suite.py +19066 -0
- setiastro/saspro/star_alignment.py +7380 -0
- setiastro/saspro/star_alignment_preset.py +329 -0
- setiastro/saspro/star_metrics.py +49 -0
- setiastro/saspro/star_spikes.py +765 -0
- setiastro/saspro/star_stretch.py +507 -0
- setiastro/saspro/stat_stretch.py +538 -0
- setiastro/saspro/status_log_dock.py +78 -0
- setiastro/saspro/subwindow.py +3407 -0
- setiastro/saspro/supernovaasteroidhunter.py +1719 -0
- setiastro/saspro/swap_manager.py +134 -0
- setiastro/saspro/torch_backend.py +89 -0
- setiastro/saspro/torch_rejection.py +434 -0
- setiastro/saspro/translations/all_source_strings.json +4726 -0
- setiastro/saspro/translations/ar_translations.py +4096 -0
- setiastro/saspro/translations/de_translations.py +3728 -0
- setiastro/saspro/translations/es_translations.py +4169 -0
- setiastro/saspro/translations/fr_translations.py +4090 -0
- setiastro/saspro/translations/hi_translations.py +3803 -0
- setiastro/saspro/translations/integrate_translations.py +271 -0
- setiastro/saspro/translations/it_translations.py +4728 -0
- setiastro/saspro/translations/ja_translations.py +3834 -0
- setiastro/saspro/translations/pt_translations.py +3847 -0
- setiastro/saspro/translations/ru_translations.py +3082 -0
- setiastro/saspro/translations/saspro_ar.qm +0 -0
- setiastro/saspro/translations/saspro_ar.ts +16019 -0
- setiastro/saspro/translations/saspro_de.qm +0 -0
- setiastro/saspro/translations/saspro_de.ts +14548 -0
- setiastro/saspro/translations/saspro_es.qm +0 -0
- setiastro/saspro/translations/saspro_es.ts +16202 -0
- setiastro/saspro/translations/saspro_fr.qm +0 -0
- setiastro/saspro/translations/saspro_fr.ts +15870 -0
- setiastro/saspro/translations/saspro_hi.qm +0 -0
- setiastro/saspro/translations/saspro_hi.ts +14855 -0
- setiastro/saspro/translations/saspro_it.qm +0 -0
- setiastro/saspro/translations/saspro_it.ts +19046 -0
- setiastro/saspro/translations/saspro_ja.qm +0 -0
- setiastro/saspro/translations/saspro_ja.ts +14980 -0
- setiastro/saspro/translations/saspro_pt.qm +0 -0
- setiastro/saspro/translations/saspro_pt.ts +15024 -0
- setiastro/saspro/translations/saspro_ru.qm +0 -0
- setiastro/saspro/translations/saspro_ru.ts +11835 -0
- setiastro/saspro/translations/saspro_sw.qm +0 -0
- setiastro/saspro/translations/saspro_sw.ts +15237 -0
- setiastro/saspro/translations/saspro_uk.qm +0 -0
- setiastro/saspro/translations/saspro_uk.ts +15248 -0
- setiastro/saspro/translations/saspro_zh.qm +0 -0
- setiastro/saspro/translations/saspro_zh.ts +15289 -0
- setiastro/saspro/translations/sw_translations.py +3897 -0
- setiastro/saspro/translations/uk_translations.py +3929 -0
- setiastro/saspro/translations/zh_translations.py +3910 -0
- setiastro/saspro/versioning.py +77 -0
- setiastro/saspro/view_bundle.py +1558 -0
- setiastro/saspro/wavescale_hdr.py +645 -0
- setiastro/saspro/wavescale_hdr_preset.py +101 -0
- setiastro/saspro/wavescalede.py +680 -0
- setiastro/saspro/wavescalede_preset.py +230 -0
- setiastro/saspro/wcs_update.py +374 -0
- setiastro/saspro/whitebalance.py +513 -0
- setiastro/saspro/widgets/__init__.py +48 -0
- setiastro/saspro/widgets/common_utilities.py +306 -0
- setiastro/saspro/widgets/graphics_views.py +122 -0
- setiastro/saspro/widgets/image_utils.py +518 -0
- setiastro/saspro/widgets/minigame/game.js +991 -0
- setiastro/saspro/widgets/minigame/index.html +53 -0
- setiastro/saspro/widgets/minigame/style.css +241 -0
- setiastro/saspro/widgets/preview_dialogs.py +280 -0
- setiastro/saspro/widgets/resource_monitor.py +263 -0
- setiastro/saspro/widgets/spinboxes.py +290 -0
- setiastro/saspro/widgets/themed_buttons.py +13 -0
- setiastro/saspro/widgets/wavelet_utils.py +331 -0
- setiastro/saspro/wimi.py +7996 -0
- setiastro/saspro/wims.py +578 -0
- setiastro/saspro/window_shelf.py +185 -0
- setiastro/saspro/xisf.py +1213 -0
- setiastrosuitepro-1.6.5.post3.dist-info/METADATA +278 -0
- setiastrosuitepro-1.6.5.post3.dist-info/RECORD +368 -0
- setiastrosuitepro-1.6.5.post3.dist-info/WHEEL +4 -0
- setiastrosuitepro-1.6.5.post3.dist-info/entry_points.txt +6 -0
- setiastrosuitepro-1.6.5.post3.dist-info/licenses/LICENSE +674 -0
- setiastrosuitepro-1.6.5.post3.dist-info/licenses/license.txt +2580 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# pro/clahe.py
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import numpy as np
|
|
4
|
+
import cv2
|
|
5
|
+
|
|
6
|
+
from PyQt6.QtCore import Qt, QTimer
|
|
7
|
+
from PyQt6.QtGui import QImage, QPixmap, QIcon
|
|
8
|
+
from PyQt6.QtWidgets import (
|
|
9
|
+
QDialog, QVBoxLayout, QHBoxLayout, QGroupBox, QGridLayout,
|
|
10
|
+
QLabel, QPushButton, QSlider, QGraphicsScene,
|
|
11
|
+
QGraphicsPixmapItem, QMessageBox
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
# Import centralized widgets
|
|
15
|
+
from setiastro.saspro.widgets.graphics_views import ZoomableGraphicsView
|
|
16
|
+
from setiastro.saspro.widgets.image_utils import extract_mask_resized as _get_active_mask_resized
|
|
17
|
+
from setiastro.saspro.widgets.themed_buttons import themed_toolbtn
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# ----------------------- Core -----------------------
|
|
21
|
+
def apply_clahe(image: np.ndarray, clip_limit: float = 2.0, tile_grid_size: tuple = (8, 8)) -> np.ndarray:
|
|
22
|
+
# ... (unchanged)
|
|
23
|
+
if image is None:
|
|
24
|
+
raise ValueError("image is None")
|
|
25
|
+
arr = np.asarray(image, dtype=np.float32)
|
|
26
|
+
arr = np.clip(arr, 0.0, 1.0)
|
|
27
|
+
was_hw1 = (arr.ndim == 3 and arr.shape[2] == 1)
|
|
28
|
+
if arr.ndim == 3 and arr.shape[2] == 3:
|
|
29
|
+
lab = cv2.cvtColor((arr * 255.0).astype(np.uint8), cv2.COLOR_RGB2LAB)
|
|
30
|
+
l, a, b = cv2.split(lab)
|
|
31
|
+
clahe = cv2.createCLAHE(clipLimit=float(clip_limit), tileGridSize=tuple(tile_grid_size))
|
|
32
|
+
cl = clahe.apply(l)
|
|
33
|
+
limg = cv2.merge((cl, a, b))
|
|
34
|
+
enhanced = cv2.cvtColor(limg, cv2.COLOR_LAB2RGB).astype(np.float32) / 255.0
|
|
35
|
+
return np.clip(enhanced, 0.0, 1.0)
|
|
36
|
+
mono = arr.squeeze()
|
|
37
|
+
clahe = cv2.createCLAHE(clipLimit=float(clip_limit), tileGridSize=tuple(tile_grid_size))
|
|
38
|
+
cl = clahe.apply((mono * 255.0).astype(np.uint8)).astype(np.float32) / 255.0
|
|
39
|
+
cl = np.clip(cl, 0.0, 1.0)
|
|
40
|
+
if was_hw1:
|
|
41
|
+
cl = cl[..., None]
|
|
42
|
+
return cl
|
|
43
|
+
|
|
44
|
+
# Note: _get_active_mask_resized imported from setiastro.saspro.widgets.image_utils
|
|
45
|
+
|
|
46
|
+
def apply_clahe_to_doc(doc, preset: dict | None):
|
|
47
|
+
"""
|
|
48
|
+
Apply CLAHE to doc.image using a preset.
|
|
49
|
+
|
|
50
|
+
Backward compatible:
|
|
51
|
+
- old presets: {"clip_limit": 2.0, "tile": 8} # tile count across min dimension
|
|
52
|
+
- new presets: {"clip_limit": 2.0, "tile_px": 128} # tile size in pixels
|
|
53
|
+
"""
|
|
54
|
+
if doc is None or getattr(doc, "image", None) is None:
|
|
55
|
+
raise RuntimeError("Document has no image.")
|
|
56
|
+
|
|
57
|
+
img = np.asarray(doc.image)
|
|
58
|
+
|
|
59
|
+
# --- preset decode (supports old + new) ---
|
|
60
|
+
p = preset or {}
|
|
61
|
+
clip = float(p.get("clip_limit", 2.0))
|
|
62
|
+
|
|
63
|
+
# Resolve tile_grid_size for OpenCV
|
|
64
|
+
if "tile_px" in p:
|
|
65
|
+
tile_px = int(p.get("tile_px", 128))
|
|
66
|
+
h, w = img.shape[:2]
|
|
67
|
+
s = float(min(h, w))
|
|
68
|
+
tile_px = max(8, tile_px)
|
|
69
|
+
n = int(round(s / float(tile_px)))
|
|
70
|
+
n = max(2, min(n, 128))
|
|
71
|
+
tile_grid = (n, n)
|
|
72
|
+
else:
|
|
73
|
+
# legacy: treat "tile" as OpenCV tileGridSize count (tiles across)
|
|
74
|
+
tile = int(p.get("tile", 8))
|
|
75
|
+
tile = max(2, min(tile, 128))
|
|
76
|
+
tile_grid = (tile, tile)
|
|
77
|
+
|
|
78
|
+
out = apply_clahe(img, clip_limit=clip, tile_grid_size=tile_grid)
|
|
79
|
+
out = np.clip(out, 0.0, 1.0).astype(np.float32, copy=False)
|
|
80
|
+
|
|
81
|
+
# Blend with active mask if present
|
|
82
|
+
H, W = out.shape[:2]
|
|
83
|
+
m = _get_active_mask_resized(doc, H, W)
|
|
84
|
+
if m is not None:
|
|
85
|
+
base = np.asarray(doc.image, dtype=np.float32)
|
|
86
|
+
if base.dtype.kind in "ui":
|
|
87
|
+
maxv = float(np.iinfo(base.dtype).max)
|
|
88
|
+
base = base / max(1.0, maxv)
|
|
89
|
+
else:
|
|
90
|
+
base = np.clip(base, 0.0, 1.0)
|
|
91
|
+
|
|
92
|
+
if out.ndim == 3:
|
|
93
|
+
if base.ndim == 2:
|
|
94
|
+
base = base[:, :, None].repeat(out.shape[2], axis=2)
|
|
95
|
+
elif base.ndim == 3 and base.shape[2] == 1:
|
|
96
|
+
base = base.repeat(out.shape[2], axis=2)
|
|
97
|
+
M = np.repeat(m[:, :, None], out.shape[2], axis=2).astype(np.float32)
|
|
98
|
+
out = np.clip(base * (1.0 - M) + out * M, 0.0, 1.0)
|
|
99
|
+
else:
|
|
100
|
+
if base.ndim == 3 and base.shape[2] == 1:
|
|
101
|
+
base = base.squeeze(axis=2)
|
|
102
|
+
out = np.clip(base * (1.0 - m) + out * m, 0.0, 1.0)
|
|
103
|
+
|
|
104
|
+
# Commit
|
|
105
|
+
if hasattr(doc, "set_image"):
|
|
106
|
+
doc.set_image(out, step_name="CLAHE")
|
|
107
|
+
elif hasattr(doc, "apply_numpy"):
|
|
108
|
+
doc.apply_numpy(out, step_name="CLAHE")
|
|
109
|
+
else:
|
|
110
|
+
doc.image = out
|
|
111
|
+
|
|
112
|
+
# ----------------------- Dialog -----------------------
|
|
113
|
+
class CLAHEDialogPro(QDialog):
|
|
114
|
+
def __init__(self, parent, doc, icon: QIcon | None = None):
|
|
115
|
+
super().__init__(parent)
|
|
116
|
+
self.setWindowTitle(self.tr("CLAHE"))
|
|
117
|
+
self.setWindowFlag(Qt.WindowType.Window, True)
|
|
118
|
+
self.setWindowModality(Qt.WindowModality.NonModal)
|
|
119
|
+
self.setModal(False)
|
|
120
|
+
if icon:
|
|
121
|
+
try: self.setWindowIcon(icon)
|
|
122
|
+
except Exception as e:
|
|
123
|
+
import logging
|
|
124
|
+
logging.debug(f"Exception suppressed: {type(e).__name__}: {e}")
|
|
125
|
+
|
|
126
|
+
self.doc = doc
|
|
127
|
+
self.orig = np.clip(np.asarray(doc.image, dtype=np.float32), 0.0, 1.0)
|
|
128
|
+
disp = self.orig
|
|
129
|
+
if disp.ndim == 2: disp = disp[..., None].repeat(3, axis=2)
|
|
130
|
+
elif disp.ndim == 3 and disp.shape[2] == 1: disp = disp.repeat(3, axis=2)
|
|
131
|
+
self._disp_base = disp
|
|
132
|
+
|
|
133
|
+
v = QVBoxLayout(self)
|
|
134
|
+
|
|
135
|
+
# ---- Params (unchanged) ----
|
|
136
|
+
grp = QGroupBox(self.tr("CLAHE Parameters")); grid = QGridLayout(grp)
|
|
137
|
+
self.s_clip = QSlider(Qt.Orientation.Horizontal); self.s_clip.setRange(1, 40); self.s_clip.setValue(20)
|
|
138
|
+
self.lbl_clip = QLabel("2.0")
|
|
139
|
+
self.s_clip.valueChanged.connect(lambda val: self.lbl_clip.setText(f"{val/10.0:.1f}"))
|
|
140
|
+
self.s_clip.valueChanged.connect(self._debounce_preview)
|
|
141
|
+
|
|
142
|
+
# tile size slider (pixels) — intuitive control
|
|
143
|
+
self.s_tile = QSlider(Qt.Orientation.Horizontal)
|
|
144
|
+
self.s_tile.setRange(8, 512) # 4 is pointless; you clamp to >=8 anyway
|
|
145
|
+
self.s_tile.setSingleStep(8)
|
|
146
|
+
self.s_tile.setPageStep(64)
|
|
147
|
+
self.s_tile.setValue(128) # nice default
|
|
148
|
+
self.s_tile.setToolTip("CLAHE tile size in pixels (larger = coarser, smaller = finer).")
|
|
149
|
+
|
|
150
|
+
self.lbl_tile = QLabel("128 px")
|
|
151
|
+
self.lbl_tile.setToolTip(self.s_tile.toolTip())
|
|
152
|
+
|
|
153
|
+
self.s_tile.valueChanged.connect(lambda v: self.lbl_tile.setText(f"{v} px"))
|
|
154
|
+
self.s_tile.valueChanged.connect(self._debounce_preview)
|
|
155
|
+
|
|
156
|
+
grid.addWidget(QLabel(self.tr("Tile Size (px):")), 1, 0)
|
|
157
|
+
grid.addWidget(self.s_tile, 1, 1)
|
|
158
|
+
grid.addWidget(self.lbl_tile, 1, 2)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
grid.addWidget(QLabel(self.tr("Clip Limit:")), 0, 0); grid.addWidget(self.s_clip, 0, 1); grid.addWidget(self.lbl_clip, 0, 2)
|
|
163
|
+
|
|
164
|
+
v.addWidget(grp)
|
|
165
|
+
|
|
166
|
+
# ---- Preview with zoom/pan ----
|
|
167
|
+
self.scene = QGraphicsScene(self)
|
|
168
|
+
self.view = ZoomableGraphicsView(self.scene)
|
|
169
|
+
self.view.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
170
|
+
self.pix = QGraphicsPixmapItem()
|
|
171
|
+
self.scene.addItem(self.pix)
|
|
172
|
+
v.addWidget(self.view, 1)
|
|
173
|
+
|
|
174
|
+
# ---- Zoom bar ----
|
|
175
|
+
# ---- Zoom bar (themed) ----
|
|
176
|
+
z = QHBoxLayout()
|
|
177
|
+
z.addStretch(1)
|
|
178
|
+
|
|
179
|
+
self.btn_zoom_in = themed_toolbtn("zoom-in", "Zoom In")
|
|
180
|
+
self.btn_zoom_out = themed_toolbtn("zoom-out", "Zoom Out")
|
|
181
|
+
self.btn_zoom_fit = themed_toolbtn("zoom-fit-best", "Fit to Preview")
|
|
182
|
+
|
|
183
|
+
self.btn_zoom_in.clicked.connect(self.view.zoom_in)
|
|
184
|
+
self.btn_zoom_out.clicked.connect(self.view.zoom_out)
|
|
185
|
+
self.btn_zoom_fit.clicked.connect(lambda: self.view.fit_to_item(self.pix))
|
|
186
|
+
|
|
187
|
+
z.addWidget(self.btn_zoom_in)
|
|
188
|
+
z.addWidget(self.btn_zoom_out)
|
|
189
|
+
z.addWidget(self.btn_zoom_fit)
|
|
190
|
+
|
|
191
|
+
v.addLayout(z)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
# ---- Buttons (unchanged) ----
|
|
195
|
+
row = QHBoxLayout()
|
|
196
|
+
self.btn_apply = QPushButton(self.tr("Apply")); self.btn_apply.clicked.connect(self._apply)
|
|
197
|
+
self.btn_reset = QPushButton(self.tr("Reset")); self.btn_reset.clicked.connect(self._reset)
|
|
198
|
+
self.btn_close = QPushButton(self.tr("Cancel")); self.btn_close.clicked.connect(self.reject)
|
|
199
|
+
row.addStretch(1); row.addWidget(self.btn_apply); row.addWidget(self.btn_reset); row.addWidget(self.btn_close)
|
|
200
|
+
v.addLayout(row)
|
|
201
|
+
|
|
202
|
+
self._timer = QTimer(self); self._timer.setSingleShot(True); self._timer.timeout.connect(self._update_preview)
|
|
203
|
+
|
|
204
|
+
self._set_pix(self._disp_base)
|
|
205
|
+
self._update_preview()
|
|
206
|
+
# initial fit
|
|
207
|
+
self.view.fit_to_item(self.pix)
|
|
208
|
+
|
|
209
|
+
def _debounce_preview(self): self._timer.start(250)
|
|
210
|
+
|
|
211
|
+
def _set_pix(self, rgb):
|
|
212
|
+
arr = (np.clip(rgb, 0, 1) * 255).astype(np.uint8)
|
|
213
|
+
h, w, _ = arr.shape
|
|
214
|
+
q = QImage(arr.data, w, h, 3*w, QImage.Format.Format_RGB888)
|
|
215
|
+
self.pix.setPixmap(QPixmap.fromImage(q))
|
|
216
|
+
self.scene.setSceneRect(self.pix.boundingRect())
|
|
217
|
+
|
|
218
|
+
def _update_preview(self):
|
|
219
|
+
clip = self.s_clip.value() / 10.0
|
|
220
|
+
tile_px = int(self.s_tile.value())
|
|
221
|
+
|
|
222
|
+
try:
|
|
223
|
+
tile_grid = self._tile_grid_from_px(tile_px, self._disp_base.shape[:2])
|
|
224
|
+
|
|
225
|
+
out = apply_clahe(
|
|
226
|
+
self._disp_base,
|
|
227
|
+
clip_limit=float(clip),
|
|
228
|
+
tile_grid_size=tile_grid
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
# Respect active mask (preview works on _disp_base size)
|
|
232
|
+
H, W = out.shape[:2]
|
|
233
|
+
m = _get_active_mask_resized(self.doc, H, W)
|
|
234
|
+
if m is not None:
|
|
235
|
+
if out.ndim == 3:
|
|
236
|
+
M = np.repeat(m[:, :, None], out.shape[2], axis=2).astype(np.float32)
|
|
237
|
+
else:
|
|
238
|
+
M = m.astype(np.float32)
|
|
239
|
+
|
|
240
|
+
base = self._disp_base.astype(np.float32, copy=False)
|
|
241
|
+
out = np.clip(base * (1.0 - M) + out * M, 0.0, 1.0)
|
|
242
|
+
|
|
243
|
+
self._set_pix(out)
|
|
244
|
+
self._preview = out
|
|
245
|
+
|
|
246
|
+
except Exception as e:
|
|
247
|
+
QMessageBox.warning(self, "CLAHE", f"Preview failed:\n{e}")
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _apply(self):
|
|
251
|
+
try:
|
|
252
|
+
clip = float(self.s_clip.value() / 10.0)
|
|
253
|
+
tile_px = int(self.s_tile.value())
|
|
254
|
+
|
|
255
|
+
tile_grid = self._tile_grid_from_px(tile_px, self.orig.shape[:2])
|
|
256
|
+
|
|
257
|
+
out = apply_clahe(
|
|
258
|
+
self.orig,
|
|
259
|
+
clip_limit=clip,
|
|
260
|
+
tile_grid_size=tile_grid
|
|
261
|
+
)
|
|
262
|
+
out = np.clip(out, 0.0, 1.0).astype(np.float32, copy=False)
|
|
263
|
+
|
|
264
|
+
# Mask-respectful commit
|
|
265
|
+
H, W = out.shape[:2]
|
|
266
|
+
m = _get_active_mask_resized(self.doc, H, W)
|
|
267
|
+
if m is not None:
|
|
268
|
+
base = np.asarray(self.doc.image, dtype=np.float32)
|
|
269
|
+
|
|
270
|
+
# Normalize base into [0..1] for blending
|
|
271
|
+
if base.dtype.kind in "ui":
|
|
272
|
+
maxv = float(np.iinfo(base.dtype).max)
|
|
273
|
+
base = base / max(1.0, maxv)
|
|
274
|
+
else:
|
|
275
|
+
base = np.clip(base, 0.0, 1.0)
|
|
276
|
+
|
|
277
|
+
if out.ndim == 3:
|
|
278
|
+
if base.ndim == 2:
|
|
279
|
+
base = base[:, :, None].repeat(out.shape[2], axis=2)
|
|
280
|
+
elif base.ndim == 3 and base.shape[2] == 1:
|
|
281
|
+
base = base.repeat(out.shape[2], axis=2)
|
|
282
|
+
|
|
283
|
+
M = np.repeat(m[:, :, None], out.shape[2], axis=2).astype(np.float32)
|
|
284
|
+
out = np.clip(base * (1.0 - M) + out * M, 0.0, 1.0)
|
|
285
|
+
else:
|
|
286
|
+
if base.ndim == 3 and base.shape[2] == 1:
|
|
287
|
+
base = base.squeeze(axis=2)
|
|
288
|
+
out = np.clip(base * (1.0 - m) + out * m, 0.0, 1.0)
|
|
289
|
+
|
|
290
|
+
out = out.astype(np.float32, copy=False)
|
|
291
|
+
|
|
292
|
+
# Commit to document
|
|
293
|
+
if hasattr(self.doc, "set_image"):
|
|
294
|
+
self.doc.set_image(out, step_name="CLAHE")
|
|
295
|
+
elif hasattr(self.doc, "apply_numpy"):
|
|
296
|
+
self.doc.apply_numpy(out, step_name="CLAHE")
|
|
297
|
+
else:
|
|
298
|
+
self.doc.image = out
|
|
299
|
+
|
|
300
|
+
# ── Register as last_headless_command for replay ─────────────
|
|
301
|
+
try:
|
|
302
|
+
main = self.parent()
|
|
303
|
+
if main is not None:
|
|
304
|
+
preset = {
|
|
305
|
+
"clip_limit": float(clip),
|
|
306
|
+
"tile_px": int(tile_px), # NEW, intuitive
|
|
307
|
+
# (optional debug)
|
|
308
|
+
# "tile": int(tile_grid[0]),
|
|
309
|
+
}
|
|
310
|
+
payload = {"command_id": "clahe", "preset": dict(preset)}
|
|
311
|
+
setattr(main, "_last_headless_command", payload)
|
|
312
|
+
|
|
313
|
+
try:
|
|
314
|
+
if hasattr(main, "_log"):
|
|
315
|
+
main._log(
|
|
316
|
+
f"[Replay] Registered CLAHE as last action "
|
|
317
|
+
f"(clip_limit={preset['clip_limit']}, tile_px={preset['tile_px']})"
|
|
318
|
+
)
|
|
319
|
+
except Exception:
|
|
320
|
+
pass
|
|
321
|
+
except Exception:
|
|
322
|
+
pass
|
|
323
|
+
# ─────────────────────────────────────────────────────────────
|
|
324
|
+
|
|
325
|
+
# Dialog stays open so user can apply to other images
|
|
326
|
+
# Refresh document reference for next operation
|
|
327
|
+
self._refresh_document_from_active()
|
|
328
|
+
|
|
329
|
+
except Exception as e:
|
|
330
|
+
QMessageBox.critical(self, "CLAHE", f"Failed to apply:\n{e}")
|
|
331
|
+
|
|
332
|
+
def _refresh_document_from_active(self):
|
|
333
|
+
"""
|
|
334
|
+
Refresh the dialog's document reference to the currently active document.
|
|
335
|
+
This allows reusing the same dialog on different images.
|
|
336
|
+
"""
|
|
337
|
+
try:
|
|
338
|
+
main = self.parent()
|
|
339
|
+
if main and hasattr(main, "_active_doc"):
|
|
340
|
+
new_doc = main._active_doc()
|
|
341
|
+
if new_doc is not None and new_doc is not self.doc:
|
|
342
|
+
self.doc = new_doc
|
|
343
|
+
# Refresh original image and preview for new document
|
|
344
|
+
self.orig = np.clip(np.asarray(new_doc.image, dtype=np.float32), 0.0, 1.0)
|
|
345
|
+
disp = self.orig
|
|
346
|
+
if disp.ndim == 2: disp = disp[..., None].repeat(3, axis=2)
|
|
347
|
+
elif disp.ndim == 3 and disp.shape[2] == 1: disp = disp.repeat(3, axis=2)
|
|
348
|
+
self._disp_base = disp
|
|
349
|
+
self._update_preview()
|
|
350
|
+
except Exception:
|
|
351
|
+
pass
|
|
352
|
+
|
|
353
|
+
def _tile_grid_from_px(self, tile_px: int, hw: tuple[int, int]) -> tuple[int, int]:
|
|
354
|
+
"""
|
|
355
|
+
Convert desired tile size (pixels) into OpenCV tileGridSize=(n,n)
|
|
356
|
+
where n is number of tiles across the *min dimension*.
|
|
357
|
+
"""
|
|
358
|
+
h, w = hw
|
|
359
|
+
s = float(min(h, w))
|
|
360
|
+
tile_px = max(8, int(tile_px))
|
|
361
|
+
n = int(round(s / float(tile_px)))
|
|
362
|
+
n = max(2, min(n, 128))
|
|
363
|
+
return (n, n)
|
|
364
|
+
|
|
365
|
+
def _reset(self):
|
|
366
|
+
self.s_clip.setValue(20); self.s_tile.setValue(8)
|
|
367
|
+
self._set_pix(self._disp_base)
|
|
368
|
+
self.view.fit_to_item(self.pix)
|