Enhance image_spectrum to return amplitude and phase
Updated RETURN_TYPES to include amplitude and phase spectra. Modified image_spectrum function to return both amplitude and phase tensors.
This commit is contained in:
+15
-9
@@ -18,7 +18,8 @@ class Image_Spectrum:
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
RETURN_TYPES = ("IMAGE", "IMAGE")
|
||||
RETURN_NAMES = ("amplitude_spectrum", "phase_spectrum")
|
||||
FUNCTION = "image_spectrum"
|
||||
CATEGORY = "image"
|
||||
|
||||
@@ -26,17 +27,22 @@ class Image_Spectrum:
|
||||
image = 255. * image[0].cpu().numpy()
|
||||
image = Image.fromarray(np.clip(image, 0, 255).astype(np.uint8))
|
||||
image = ImageOps.grayscale(image)
|
||||
|
||||
|
||||
# 2D Fourier 변환 수행
|
||||
f_transform = fft2(image)
|
||||
f_shift = fftshift(f_transform)
|
||||
spectrum = amplitude*np.log1p(np.abs(f_shift))
|
||||
|
||||
image = np.array(spectrum).astype(np.float32) / 255.0
|
||||
mask = 1. - torch.from_numpy(image)
|
||||
image = torch.from_numpy(image)[None,]
|
||||
|
||||
return (image,)
|
||||
|
||||
# 진폭 스펙트럼
|
||||
spectrum = amplitude * np.log1p(np.abs(f_shift))
|
||||
amp_img = np.array(spectrum).astype(np.float32) / 255.0
|
||||
amp_tensor = torch.from_numpy(amp_img)[None,]
|
||||
|
||||
# 위상 스펙트럼 (-π ~ π → 0 ~ 1 정규화)
|
||||
phase = np.angle(f_shift)
|
||||
phase_img = ((phase + np.pi) / (2 * np.pi)).astype(np.float32)
|
||||
phase_tensor = torch.from_numpy(phase_img)[None,]
|
||||
|
||||
return (amp_tensor, phase_tensor)
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"Image_Spectrum": Image_Spectrum
|
||||
|
||||
Reference in New Issue
Block a user