Skip to main content
3 of 8
added 30 characters in body
lio
  • 2.4k
  • 14
  • 26

How to add a legend showing the amplitudes instead of brightness values:

With the help of Julien Kluges answer I have the following code, which is also showing the "frequency" along the axes:

img = ColorConvert[ExampleData[{"TestImage", "Lena"}], "Grayscale"];
   
fft = Fourier[ImageData[img]];
fft = RotateLeft[fft, Floor[Dimensions[fft]/2]];
    
fftAbsData = Log[Abs[fft]] - Min[Log[Abs[fft]]];
    
{fftAbsMin, fftAbsMax} = MinMax[fftAbsData];

myColorTable = 
  Flatten@{Table[{Blend[{Blue, Green, Yellow, Orange, Red}, x]}, {x, 1/256, 1, 1/256}]};

g = Show[
      Colorize[Image[(fftAbsData - fftAbsMin)/(fftAbsMax - fftAbsMin)], 
        ColorFunction -> (Blend[myColorTable, #] &)]
    ];

myLegend = 
  BarLegend[
    {myColorTable, {Exp[fftAbsMin + Min[Log[Abs[fft]]]], 
    Exp[fftAbsMax + Min[Log[Abs[fft]]]]}}, 
    LegendLabel -> "amplitude", LegendMarkerSize -> {40, 300}, 
    LabelStyle -> {FontFamily -> "Calibri", FontSize -> 15}
  ];

Legended[
  Graphics[
    Inset[g, Scaled[{.5, .5}], Automatic, Scaled[1]], Frame -> True, 
    FrameLabel -> {{"cycles/pixel", ""}, {"cycles/pixel", ""}}, 
    PlotRange -> {{-0.5, 0.5}, {-0.5, 0.5}}, 
    AspectRatio -> ImageAspectRatio@g
  ]
  , myLegend
]

enter image description here

lio
  • 2.4k
  • 14
  • 26