import numpy as np import matplotlib.pyplot as plt import cv2 as cv from matplotlib.image import imread from scipy.spatial import distance  # List to store clicked points points = []  # Conversion factors from pixels to micrometers for different grinding types conversion_factors = {     "R": 100 / 24,  # 100 µm / 24 pixels     "M": 100 / 69,  # 100 µm / 69 pixels     "F": 100 / 90   # 100 µm / 90 pixels }  def find_coord(event, x, y, flags, params):     global points     if event == cv.EVENT_LBUTTONDOWN:         print(f"Clicked at: ({x}, {y})")         points.append((x, y))         new_img = img_reconstructed.copy()  # Changed to use the reconstructed image          cv.putText(new_img, f"{x},{y}", (x, y), cv.FONT_HERSHEY_PLAIN, 1, (255, 0, 0), 2)          if len(points) == 2:             pt1, pt2 = points             cv.line(new_img, pt1, pt2, (0, 255, 0), 2)             dist_pixels = distance.euclidean(pt1, pt2)             dist_micrometers = dist_pixels * conversion_factor             distance_text = f"Distance: {dist_micrometers:.2f} µm"             mid_point = (int((pt1[0] + pt2[0]) / 2), int((pt1[1] + pt2[1]) / 2))             cv.putText(new_img, distance_text, mid_point, cv.FONT_HERSHEY_PLAIN, 1, (255, 255, 255), 2, cv.LINE_AA)             print(distance_text)             cv.imshow("Reconstructed Image", new_img)  # Update the window title             points.clear()  def process_image(image_path):     global img, img_reconstructed     img = imread(image_path)          if img.ndim == 3:         img = np.mean(img, axis=2)      # Compute FFT and process     fft_result = np.fft.fft2(img)     fft_shift = np.fft.fftshift(fft_result)      thickness = 5     center_row = fft_shift.shape[0] // 2     center_col = fft_shift.shape[1] // 2      fft_shift_with_line = np.copy(fft_shift)     for offset in range(-thickness // 2, thickness // 2 + 1):         fft_shift_with_line[center_row + offset, :] = 0         fft_shift_with_line[center_row + offset, center_col] = fft_shift[center_row + offset, center_col]      magnitude_spectrum = np.log(np.abs(fft_shift_with_line) + 1)      ifft_shift = np.fft.ifftshift(fft_shift_with_line)     img_reconstructed = np.fft.ifft2(ifft_shift)     img_reconstructed = np.real(img_reconstructed)      plt.figure(figsize=(15, 5))     plt.subplot(1, 3, 1)     plt.title("Original Image")     plt.imshow(img, cmap='gray')     plt.subplot(1, 3, 2)     plt.title("Magnitude Spectrum with Thick Line")     plt.imshow(magnitude_spectrum, cmap='gray')     plt.subplot(1, 3, 3)     plt.title("Reconstructed Image")     plt.imshow(img_reconstructed, cmap='gray')     plt.show()  if __name__ == "__main__":     image_path = '/Users/abhi/Downloads/Zerodur/Sample 2_Medium.tif'  # Change to a valid image path     process_image(image_path)      # Now we show the reconstructed image for distance measurement     cv.imshow("Reconstructed Image", img_reconstructed / np.max(img_reconstructed))  # Normalize to display     grinding_type = input("Select grinding type (R for Rough, M for Medium and F for Fine): ").strip().capitalize()          while grinding_type not in conversion_factors:         grinding_type = input("Invalid input. Select grinding type (Rough, Medium, Fine): ").strip().capitalize()          conversion_factor = conversion_factors[grinding_type]     cv.setMouseCallback("Reconstructed Image", find_coord)     cv.waitKey(0)     cv.destroyAllWindows()-> in this code, when i click the points on the reconstructed image, it is being inverted for some reason. fix this