This commit is contained in:
2026-01-16 10:30:13 +02:00
parent 89e47591db
commit 0c19ea2557

View File

@@ -37,7 +37,7 @@ def get_pseudo_rgb(arr: np.ndarray, gamma: float = 0.5) -> np.ndarray:
a1[a1 > p999] = p999 a1[a1 > p999] = p999
a1 /= a1.max() a1 /= a1.max()
if 0: if 1:
a2 = a1.copy() a2 = a1.copy()
a2 = a2**gamma a2 = a2**gamma
a2 /= a2.max() a2 /= a2.max()
@@ -47,9 +47,12 @@ def get_pseudo_rgb(arr: np.ndarray, gamma: float = 0.5) -> np.ndarray:
a3[a3 > p9999] = p9999 a3[a3 > p9999] = p9999
a3 /= a3.max() a3 /= a3.max()
return np.stack([a1, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0) # return np.stack([a1, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0)
# return np.stack([a2, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0) # return np.stack([a2, np.zeros(a1.shape), np.zeros(a1.shape)], axis=0)
# return np.stack([a1, a2, a3], axis=0) out = np.stack([a1, a2, a3], axis=0)
# print(any(np.isnan(out).flatten()))
return out
class ImageLoadError(Exception): class ImageLoadError(Exception):
@@ -122,7 +125,7 @@ class Image:
if self.path.suffix.lower() in [".tif", ".tiff"]: if self.path.suffix.lower() in [".tif", ".tiff"]:
self._data = imread(str(self.path)) self._data = imread(str(self.path))
else: else:
raise NotImplementedError("RGB is not implemented") # raise NotImplementedError("RGB is not implemented")
# Load with OpenCV (returns BGR format) # Load with OpenCV (returns BGR format)
self._data = cv2.imread(str(self.path), cv2.IMREAD_UNCHANGED) self._data = cv2.imread(str(self.path), cv2.IMREAD_UNCHANGED)
@@ -246,27 +249,33 @@ class Image:
if self.channels == 1: if self.channels == 1:
img = get_pseudo_rgb(self.data) img = get_pseudo_rgb(self.data)
self._dtype = img.dtype self._dtype = img.dtype
return img return img, True
raise NotImplementedError
if self._channels == 3: elif self._channels == 3:
return cv2.cvtColor(self._data, cv2.COLOR_BGR2RGB) return cv2.cvtColor(self._data, cv2.COLOR_BGR2RGB), False
elif self._channels == 4: elif self._channels == 4:
return cv2.cvtColor(self._data, cv2.COLOR_BGRA2RGBA) return cv2.cvtColor(self._data, cv2.COLOR_BGRA2RGBA), False
else: else:
return self._data raise NotImplementedError
# else:
# return self._data
def get_qt_rgb(self) -> np.ascontiguousarray: def get_qt_rgb(self) -> np.ascontiguousarray:
# we keep data as (C, H, W) # we keep data as (C, H, W)
_img = self.get_rgb() _img, pseudo = self.get_rgb()
img = np.zeros((self.height, self.width, 4), dtype=np.float32) if pseudo:
img[..., 0] = _img[0] # R gradient img = np.zeros((self.height, self.width, 4), dtype=np.float32)
img[..., 1] = _img[1] # G gradient img[..., 0] = _img[0] # R gradient
img[..., 2] = _img[2] # B constant img[..., 1] = _img[1] # G gradient
img[..., 3] = 1.0 # A = 1.0 (opaque) img[..., 2] = _img[2] # B constant
img[..., 3] = 1.0 # A = 1.0 (opaque)
return np.ascontiguousarray(img) return np.ascontiguousarray(img)
else:
return np.ascontiguousarray(_img)
def get_grayscale(self) -> np.ndarray: def get_grayscale(self) -> np.ndarray:
""" """