Spaces:
Sleeping
Sleeping
AMontiB commited on
Commit ·
8e9829e
1
Parent(s): 4e5c888
update
Browse files
CFA.py
CHANGED
|
@@ -46,12 +46,23 @@ def GetMap(image_channel):
|
|
| 46 |
return e.ravel()
|
| 47 |
|
| 48 |
def getFourier(prob):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
imFft = np.fft.fftshift(np.fft.fft2(prob))
|
|
|
|
|
|
|
| 50 |
imFft = np.abs(imFft)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
imFft =
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
return imFft
|
| 56 |
|
| 57 |
# --- New Gradio Interaction Functions ---
|
|
@@ -110,13 +121,13 @@ def analyze_region(original_image: np.ndarray, box_coords: tuple):
|
|
| 110 |
prob_map = prob_flat.reshape(prob_map_shape)
|
| 111 |
|
| 112 |
print("3. Computing Fourier transform...")
|
| 113 |
-
fft_result = getFourier(
|
| 114 |
|
| 115 |
# Plotting
|
| 116 |
fig, axs = plt.subplots(1, 3, figsize=(12, 4))
|
| 117 |
axs[0].imshow(patch); axs[0].set_title("Selected 128x128 Patch"); axs[0].axis("off")
|
| 118 |
axs[1].imshow(prob_map, cmap='gray'); axs[1].set_title("Probability Map"); axs[1].axis("off")
|
| 119 |
-
axs[2].imshow(fft_result, cmap='gray'); axs[2].set_title("Fourier Transform"); axs[2].axis("off")
|
| 120 |
plt.tight_layout()
|
| 121 |
|
| 122 |
print(f"4. Analysis complete in {time.time() - start_time:.2f} seconds.")
|
|
|
|
| 46 |
return e.ravel()
|
| 47 |
|
| 48 |
def getFourier(prob):
|
| 49 |
+
#imFft = np.fft.fftshift(np.fft.fft2(prob))
|
| 50 |
+
#imFft = np.abs(imFft)
|
| 51 |
+
#if np.max(imFft) > 0:
|
| 52 |
+
# imFft = (imFft / np.max(imFft) * 255)
|
| 53 |
+
#imFft = imFft.astype(np.uint8)
|
| 54 |
+
#imFft = (imFft > (0.5 * 255)).astype(np.uint8)
|
| 55 |
+
# Compute the Fourier Transform and shift zero frequency to the center
|
| 56 |
imFft = np.fft.fftshift(np.fft.fft2(prob))
|
| 57 |
+
|
| 58 |
+
# Take the magnitude (absolute value)
|
| 59 |
imFft = np.abs(imFft)
|
| 60 |
+
|
| 61 |
+
# Convert to 8-bit unsigned integer (similar to uint8 in MATLAB)
|
| 62 |
+
imFft = np.uint8(imFft)/255
|
| 63 |
+
|
| 64 |
+
# Binarize the image with a threshold of 0.5
|
| 65 |
+
imFft = (imFft > 0.5).astype(np.uint8)
|
| 66 |
return imFft
|
| 67 |
|
| 68 |
# --- New Gradio Interaction Functions ---
|
|
|
|
| 121 |
prob_map = prob_flat.reshape(prob_map_shape)
|
| 122 |
|
| 123 |
print("3. Computing Fourier transform...")
|
| 124 |
+
fft_result = getFourier(prob_map)
|
| 125 |
|
| 126 |
# Plotting
|
| 127 |
fig, axs = plt.subplots(1, 3, figsize=(12, 4))
|
| 128 |
axs[0].imshow(patch); axs[0].set_title("Selected 128x128 Patch"); axs[0].axis("off")
|
| 129 |
axs[1].imshow(prob_map, cmap='gray'); axs[1].set_title("Probability Map"); axs[1].axis("off")
|
| 130 |
+
axs[2].imshow(np.abs(fft_result), cmap='gray'); axs[2].set_title("Fourier Transform"); axs[2].axis("off")
|
| 131 |
plt.tight_layout()
|
| 132 |
|
| 133 |
print(f"4. Analysis complete in {time.time() - start_time:.2f} seconds.")
|