Added high-res pass
This commit is contained in:
@ -15,6 +15,11 @@ class OpenImageWidget(PipelineStageWidget):
|
||||
super().__init__(manager, logger, default_stage_out="opened_image")
|
||||
self.dialog_tag = dpg.generate_uuid()
|
||||
self.output_tag = dpg.generate_uuid()
|
||||
self.img = None
|
||||
self.img_full = None
|
||||
|
||||
self.manager.bus.subscribe(
|
||||
"process_full_res", self._on_process_full_res, True)
|
||||
|
||||
def create_pipeline_stage_content(self):
|
||||
with dpg.file_dialog(
|
||||
@ -46,9 +51,30 @@ class OpenImageWidget(PipelineStageWidget):
|
||||
self.logger.info(f"Selected file '{selection}'")
|
||||
try:
|
||||
img = Image.open(selection).convert("RGBA")
|
||||
arr = np.asarray(img).astype(np.float32) / \
|
||||
rgba = np.asarray(img).astype(np.float32) / \
|
||||
255.0 # normalize to [0,1]
|
||||
# Publish into pipeline
|
||||
self.manager.pipeline.publish(self.pipeline_stage_out_id, arr)
|
||||
h, w, _ = rgba.shape
|
||||
|
||||
# scale for small version
|
||||
max_dim = 500
|
||||
scale = min(1.0, max_dim / w, max_dim / h)
|
||||
if scale < 1.0:
|
||||
# convert to 0–255 uint8, resize with PIL, back to float32 [0–1]
|
||||
pil = Image.fromarray(
|
||||
(rgba * 255).astype(np.uint8), mode="RGBA")
|
||||
new_w, new_h = int(w * scale), int(h * scale)
|
||||
pil = pil.resize((new_w, new_h), Image.LANCZOS)
|
||||
rgba_small = np.asarray(pil).astype(np.float32) / 255.0
|
||||
w_small, h_small = new_w, new_h
|
||||
|
||||
self.img_full = rgba
|
||||
self.img = rgba_small
|
||||
|
||||
self.manager.pipeline.publish(
|
||||
self.pipeline_stage_out_id, rgba_small)
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to load image {selection}: {e}")
|
||||
|
||||
def _on_process_full_res(self, data):
|
||||
self.manager.pipeline.publish(
|
||||
self.pipeline_stage_out_id, self.img_full, True)
|
||||
|
Reference in New Issue
Block a user