<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="ltr">
<div>
<div>
<div>Thanks Matt, I agree that the more appropriate thing to do would be to document better, but maybe only in the ForwardFFT filter instead of ImageBase?<br>
<br>
I can imagine experiments where the input images are in the frequency domain: photo detectors in scattering ( from this search [1], these images [2] for example). In this case origin and spacing metadata make sense as they are, even though the experimenters
know the physical units of the images are in hertz, not in meters.<br>
<br>
</div>
<div>The problem with the metadata arises exclusively doing the FFT. If we modify it, we will lose the input image metadata. If we don't, the metadata of the output requires extra knowledge and read the documentation to be meaningful.<br>
<br>
</div>
<div>Also the Origin is tricky... the first bin, or index {0}, of the output of an FFT depends on the frequency layout of the algorithm, usually in the "standard" layout, it corresponds to zero frequency [3]. So the Origin(Frequency) will be 0.0 if we understand
the origin with the value of the first index..., but if the FFT is shifted, the first index would be now a large, negative frequency.<br>
</div>
<div><br>
</div>
</div>
<div>In the ExternalModule, I am using a FrequencyIterator, derived from a regular ImageRegionIterator. It adds a GetFrequency() function, providing an abstraction to let the user stop worrying about the specifics of the frequency layout.<br>
There are 3 different layouts, Regular, FFTLayout, and ShiftedFFTLayout.<br>
- Regular is a normal iterator, with GetFrequency() calling Get(), for the case I commented when the image is taken in the frequency domain, but the user needs to use the IsotropicWavelet module on it (which requires frequency iterators).<br>
</div>
<div>- FFTLayout is the standard FFT layout, vnl, fftw, and I think python uses it as well. This is the default type.<br>
</div>
<div>- ShiftedFFTLayout, the layout after shifting the FFT.<br>
<br>
</div>
<div>This allows to iterate an image from the frequency domain, and get the frequency value, the frequency bin, as well as actual value of the current pixel.<br>
And also they are a good place to store frequency 'metadata' information such as FrequencyOrigin, and FrequencySpacing, that depends on the frequency layout: See [4]
<br>
<br>
</div>
<div>Cheers,<br>
</div>
<div>Pablo<br>
</div>
<div><br>
[1] <a href="https://www.google.co.nz/search?q=photo+detector+scattering+result&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjK2NbzntzSAhUEmZQKHZenBU4Q_AUIBigB&biw=1920&bih=947#imgrc=OA28hyPkRDniVM" target="_blank">
https://www.google.co.nz/searc<wbr>h?q=photo+detector+scattering+<wbr>result&source=lnms&tbm=isch&sa<wbr>=X&ved=0ahUKEwjK2NbzntzSAhUEmZ<wbr>QKHZenBU4Q_AUIBigB&biw=1920&bi<wbr>h=947#imgrc=OA28hyPkRDniVM</a>:<br>
<br>
[2] <a href="http://www.azom.com/article.aspx?ArticleID=12502" target="_blank">http://www.azom.com/article.as<wbr>px?ArticleID=12502</a><br>
<br>
</div>
<div>
<div>[3] <a href="https://docs.scipy.org/doc/numpy/reference/routines.fft.html" target="_blank">
https://docs.scipy.org/doc/num<wbr>py/reference/routines.fft.html<br>
</a><br>
[4] <a href="https://github.com/phcerdan/ITKIsotropicWavelets/blob/master/include/itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h#L288">
https://github.com/phcerdan/ITKIsotropicWavelets/blob/master/include/itkFrequencyFFTLayoutImageRegionConstIteratorWithIndex.h#L288</a></div>
</div>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Mar 17, 2017 at 8:43 AM, <a href="mailto:matt.mccormick@kitware.com">
matt.mccormick@kitware.com</a> <span dir="ltr"><<a href="mailto:matt.mccormick@kitware.com" target="_blank">matt.mccormick@kitware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Pablo,<br>
<br>
Thanks for discussing this issue and the excellent overview of the<br>
topic. The meaning of metadata in the frequency domain could<br>
definitely a source of confusion and bugs, and we would benefit from a<br>
clarity and consensus on the subject.<br>
<br>
For practical reasons of pipeline use and existing algorithm<br>
application, re-use of itk::Image as much about seems beneficial.<br>
<br>
What do you think about adding documentation to<br>
itk::ImageBase::GetSpacing() [1]? We could state that the Spacing is<br>
always in physical units. If the image is in the frequency domain,<br>
then Spacing is equal to 1 / Frequency Sampling and the Frequency Bin<br>
Resolution equals 1 / (Frequency Sampling * N), where N is the Size of<br>
the LargestPossibleImageRegion (but not in the half-Hermitian<br>
storage).<br>
<br>
Then, the frequency shrinkage filter would increase its output Spacing<br>
accordingly so metadata is updated throughout an analysis pipeline.<br>
<br>
Thanks,<br>
Matt<br>
<br>
[1] <a href="https://itk.org/Doxygen/html/classitk_1_1ImageBase.html#aaadef7c0a9627cf22b0fbf2de6de913c" rel="noreferrer" target="_blank">
https://itk.org/Doxygen/html/<wbr>classitk_1_1ImageBase.html#<wbr>aaadef7c0a9627cf22b0fbf2de6de9<wbr>13c</a><br>
<div>
<div class="h5"><br>
On Tue, Mar 14, 2017 at 4:54 AM, Pablo Hernández<br>
<<a href="mailto:pablo.hernandez.cerdan@outlook.com">pablo.hernandez.cerdan@<wbr>outlook.com</a>> wrote:<br>
> Hey there,<br>
><br>
> I am contributing with the IsotropicWavelet external module, and I am facing<br>
> some doubts about the meaning of image metadata in frequency-domain images.<br>
><br>
> Current behavior performing a FFTforward is to copy the input image<br>
> metadata: spacing,origin, and direction to the output, even though the<br>
> output is in the frequency domain or dual space. I guess it is better copy<br>
> it than to lose it, but doesn't mean that the metadata is meaningful in the<br>
> frequency domain. Spacing information can led the user to think that between<br>
> each pixel holding a frequency value, that spacing is like a frequency<br>
> resolution, but it is not.<br>
><br>
> Some refresh of the lingo to help:<br>
> dual space: f ~ 1/T (where T can represent time or space)<br>
> Units of frequency are: Hertz = 1 / [ T ], or Radians (Rad = 2pi Hz)<br>
> Spacing (or Sampling in the lingo of digital signaling processing) in a<br>
> spatial domain image is associated with the resolution of the image, and<br>
> represents the pixel width in physical units.<br>
> The Origin is an array holding some relative units to world coordinates that<br>
> are meaningful for the experimenter.<br>
><br>
> What does spacing mean in a frequency domain image? The frequency resolution<br>
> after an FFT is related to the size of the FFT (the size of the image) and<br>
> the sampling rate of the original image (more here).<br>
><br>
> Freq_bin_resolution = Freq_sampling / N. Where N is the size of the image,<br>
> and Freq_sampling = 1 / Spacing. All these variables are arrays, with size<br>
> equal to the dimension of the image.<br>
><br>
> And the origin, in the case of the output of an FFT, depends on the layout<br>
> of that particular FFT algorithm. VNL and FFTW share the same layout, where,<br>
> for example, the zero frequency bin is stored the first index {{0}} , (also<br>
> note that the physical units of that first index is always 0.0 Hz,<br>
> regardless of origin, or spacing of the original image).<br>
><br>
> If we set the Freq_sampling to {{1.0}} (corresponding to a Spacing of<br>
> {{1.0}}, then the freq resolution will be {{1/N}} (depending on the size!),<br>
> and the range of frequencies will always be: (-0.5, 0.5] Hz, or (-pi, pi]<br>
> rads (independent of the size).<br>
><br>
> So right now, in the wavelet module that works in the frequency domain, and<br>
> does some shrinkage in this domain, I have chosen to ignore all this<br>
> metadata, and let the user recover it if he/she needs it, but it might be<br>
> worth to think about this.<br>
><br>
> For example, in a shrinkage by a factor of 2, the width of a pixel<br>
> representing a frequency, doubles. F_bin_resolution =1/(N/2) = 2/N, and the<br>
> range of allowed frequencies keeps the same: (-Freq_sampling/2.0,<br>
> Freq_sampling/2.0] or (-0.5, 0.5] or (-pi,pi] if Freq_sampling =1.0<br>
><br>
> This is all good, but hard to grasp when the metadata can be misleading. If<br>
> you have any thoughts on how to improve this or be clearer to the user,<br>
> happy to hear, meanwhile I think I will keep ignoring any metadata<br>
> associated with the spatial domain when dealing with frequency domain<br>
> images.<br>
><br>
> Cheers,<br>
> Pablo<br>
><br>
</div>
</div>
> ______________________________<wbr>_______<br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">
http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">
http://www.kitware.com/<wbr>products/protraining.php</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">
http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
><br>
</blockquote>
</div>
<br>
</div>
</body>
</html>