Package: hdaf-filter
2D/3D filtering (low-pass, high-pass, band-pass, laplacian, and multi-scale laplacian) in Fourier SpacePython implementation of a low-pass filter based on Hermited Distributed Approximating Functionals (hdaf), which can be used to create additional filters such as high-pass, band-pass, laplacian and multi-scale laplacian. The references are the followings:Low-pass filterHoffman, D.K., & Nayar, N. (1991).Analytic banded approximation for the discretized free propagator. Journal of Physical Chemistry, 95, 8299â€“8305.Bodmann, B.G., Hoffman, D.K., Kouri, D.J. et al.Hermite Distributed Approximating Functionals as Almost-Ideal Low-Pass FiltersSTSIP 7, 15â€“38 (2008).https://doi.org/10.1007/BF03549483high-pass, band-pass, laplacianD. JimÃ©nez, M. Papadakis, D. Labate and I. A. Kakadiaris, "Improved automatic centerline tracing for dendritic structures," 2013 IEEE 10th International Symposium on Biomedical Imaging, 2013, pp. 1050-1053,doi: 10.1109/ISBI.2013.6556658.JimÃ©nez, D., Labate, D., Kakadiaris, I.A. et al. Improved Automatic Centerline Tracing for Dendritic and Axonal Structures. Neuroinform 13, 227â€“244 (2015).https://doi.org/10.1007/s12021-014-9256-zMulti-scale laplacianHernandez-Herrera, P., Papadakis, M., & Kakadiaris, I. A. (2016). Multi-scale segmentation of neurons based on one-class classification. Journal of neuroscience methods, 266, 94-106.https://doi.org/10.1016/j.jneumeth.2016.03.019Please cite the paper(s) if you are using this code in your research.OverviewThe current python implementation is designed to filter the 2D/3D image in the frequency domain. The implementation requires 3 input parameters aninput image, thefiltersto be used, and the filterÂ´ssize. It consist of the following steps:Compute the fourier transform of the input image (img)img_FT = np.fft.fftn(img)Construct the required filter in the fourier spacefilter_Filter the image by applying the filter to the image. This step is done by point-wise multiplicationfiltered_ = filter_ * img_FTReturn the image to the spatial domain by applying the inverse fourier transformimg_spatial_domain = np.fft.ifftn(img)img_spatial_domain = np.real(img_spatial_domain)Repeat step 2 to 5 for each filter (low-pass, high-pass, band-pass, laplacian).Multi-scale laplacian filter requires a sligtly modification of these steps see paperMESONImportant noteThe low_pass filter is designed to resemble an almost ideal low-pass filter by setting the band transition to decrease rapidily at the cut-off frequency (n=60). The speed of decrease can be controlled by the valuenin the low pass filter (see paper D. JimÃ©nez et al. 2015 and P. Hernandez-Herrera 2016). In the implementation it is controled by hdaf.set_n(n), if the value is set to n=0 the filter in the spatial domain correspond to a GAUSSIAN FILTER. Hence, the code can be use for Gaussian filtering including DoG with the band_pass filter.The following figure depicts the speed of decrease at the cut-off valueInstalationRequirementsTested on Unix (Ubuntu 22.04) and Windows 11Tested on Python 3.7.13 (Google Colab) and Python 3.10.5 (locally)InstructionsIt is recomended to create a local virtual enviroment. However, this step can be skippedOpen terminal and move to a folder where you want to create the virtual enviromentpip install venvpython -m venv env_hdaf_filterActivate the virtual enviroment.Note: you always need to activate the virtual enviroment before runing the hdaf_filter moduleWindows:.\env_hdaf_filter\Scripts\activateUnix:source env_hdaf_filter/bin/activateInstall hadf_filter modulePyPi:pip install hdaf_filter==0.1.1Github:pip install git+https://github.com/paul-hernandez-herrera/hdaf_filtering.gitUsageUsing Python scriptUse this Google Colab (requires a gmail account)to test the hdaf_filter modlude in a sample imageIf you want to use it locally follow this steps:Import the module usingfrom hdaf_filter import hdaf, input_outputOpen an 2D or 3D imageimg = input_output.imread(file_path)wherefile_pathis the path to the input image.Create an object of the module:obj = hdaf.filt(img)Apply any filter with the appropiate radius parameter:output1 = obj.apply_filter("low_pass", 3)output2 = obj.apply_filter("low_pass", 5)output3 = obj.apply_filter("high_pass", 1)output4 = obj.apply_filter("band_pass", [2,6])output5 = obj.apply_filter("laplacian", 2)output6 = obj.apply_filter("laplacian_multiscale",[2,3,5,7,10])output7 = obj.apply_filter("laplacian_multiscale",[1,3,4])Using terminalOpen a terminal, and activate the virtual enviroment (Step 1.iv from Instructions) in case you created it.Run the command:python -m hdaf_filter --input_file path_to_input_file parameters_file path_to_parameters_filewherepath_to_input_fileis the path pointing to the input file to process with extensiontifor a folder containingtifimages. It can be 2D or 3D image stack, andpath_to_parameters_fileis the path pointing to a file containing the list of filters to be applied and the parametersThe following image shows an example of parameters fileThis file indicates that the module will apply low pass filter, high pass filter, and laplacian with radius 2, 3, 5, 7, and 10. It will output 15 different results.It will also apply 2 times the multiscale laplacian filter, first with radii equal to 2, 4, 6, 8, and 10 and next radii equal to 1,2, 3, 4. It will output only two results.Finally, the band-pass filter will be applied with radii [2,3], [3,5], [4,6], [5,8] and [5,10]. It will output five deferent results.The output of applying the filters and an image will be generated in the current working directory.Additional parameters in terminal:--save_output: Use this flag to avoid writing the output to disk--save_plot: Use this flag to avoid writing the figure to disk--folder_output path_to_folder_output: set this flag to save the output (tif output or png plot) to the desired location given by the folderpath_to_folder_outputExample of applying the filter to an imageLow-pass filterThe low-pass filter allows to pass the low frequencies and elliminating (setting to low values close to zero) the high-frequencies. This filter is usefult to remove noise in the image. The following images depict examples of low-pass filtersHigh-pass filterThe high-pass filter allows to pass the high frequencies and elliminating (setting to low values close to zero) the low-frequencies. This filter is useful to retain large changes of intensity. The following images depict examples of high-pass filtersBand-pass filterThe band-pass filter allows to pass only a band of frequencies and elliminating (setting to low values close to zero) the frequencies outside the band. The following images depict examples of high-pass filtersLaplacian filterThe laplacian filter smooth the image using the HDAF filter and the apply the laplacian. This filter is useful to detect edges. The following images depict examples of laplacian filtersLaplacian multiscaleThe laplacian multiscale smooth the image using the HDAF filter at several radius and the apply the laplacian. Then, for each pixel/voxel it selects the radius that has the laplacian with the best reponse. This filter is useful to detect edges. The following images depict examples of laplacian filters