Files
Robust_image_source_identif…/datasets/raise/fft/analyze_fft_ellipses.py

67 lines
2.9 KiB
Python

import matplotlib.pyplot as plt
from enum import Enum, auto
import itertools
class Axis(Enum):
ABSCISSA = auto()
ORDINATE = auto()
def __str__(self):
return self.name.title()
INTERESTING_VALUES_OF_AXES = {
Axis.ABSCISSA: [0, 30, 60, 84, 108, 132, 160, 179],
Axis.ORDINATE: [0, 25, 40, 55, 70, 85, 100, 117, 135, 150, 167, 182],
}
halfHeight, halfWidth = np.array(secondImage.shape) // 2
PROFILES_OF_AXES = {
Axis.ABSCISSA: secondImage[halfHeight , halfWidth:],
Axis.ORDINATE: secondImage[halfHeight:, halfWidth ],
}
colorsOfAxes = {}
for axis in Axis:
plt.suptitle('Profiles of Fourier transform axes')
plt.title('Local extremas have been listed manually from the Fourier transform visualization')
plt.xlabel('Fourier transform axis')
plt.ylabel('Fourier transform logarithmic intensity')
height, width = secondImage.shape
axisProfile = PROFILES_OF_AXES[axis]
colorsOfAxes[axis] = plt.plot(axisProfile, label = axis)[0].get_color()
for axis in Axis:
for interestingValueOfAxisIndex, interestingValueOfAxis in enumerate(INTERESTING_VALUES_OF_AXES[axis]):
linestyle = ':' if interestingValueOfAxisIndex % 2 == 0 else '--'
label = f'{axis} local {"minimum" if interestingValueOfAxisIndex == 0 else "maximum"}' if interestingValueOfAxisIndex <= 1 else None
plt.axvline(interestingValueOfAxis, color = colorsOfAxes[axis], alpha = 0.3, linestyle = linestyle, label = label)
def flattenDictValues(dict_):
return itertools.chain(*dict_.values())
# TODO: How to avoid hardcoding the default color being `black`?
MATPLOTLIB_DEFAULT_COLOR = 'black'
allInterestingValuesOfAxes = list(set(flattenDictValues(INTERESTING_VALUES_OF_AXES)))
ticks = list(plt.xticks()[0]) + allInterestingValuesOfAxes
plt.xticks(ticks)
for tickIndex, tick in enumerate(ticks):
for axis in Axis:
if tick in INTERESTING_VALUES_OF_AXES[axis]:
pltTick = plt.xticks()[1][tickIndex]
pltTick.set_color(MATPLOTLIB_DEFAULT_COLOR if axis == list(Axis)[-1] and pltTick.get_color() != MATPLOTLIB_DEFAULT_COLOR else colorsOfAxes[axis])
# TODO: Changing tick color would be nice too, see https://stackoverflow.com/questions/49997934/change-color-of-specific-ticks-at-plot-with-matplotlib#comment108290728_49998338
allInterestingValuesOfAxesMin = min(allInterestingValuesOfAxes)
allInterestingValuesOfAxesMax = max(allInterestingValuesOfAxes)
plt.xlim(allInterestingValuesOfAxesMin, allInterestingValuesOfAxesMax)
INTERESTING_PROFILES_OF_AXES = {axis: PROFILES_OF_AXES[axis][allInterestingValuesOfAxesMin:allInterestingValuesOfAxesMax + 1] for axis in Axis}
allInterestingIntensitiesOfAxes = list(flattenDictValues(INTERESTING_PROFILES_OF_AXES))
allInterestingIntensitiesOfAxesMin = min(allInterestingIntensitiesOfAxes)
allInterestingIntensitiesOfAxesMax = max(allInterestingIntensitiesOfAxes)
plt.ylim(allInterestingIntensitiesOfAxesMin, allInterestingIntensitiesOfAxesMax)
plt.legend()
plt.show()