├── .gitignore ├── Matlab ├── .gitignore ├── README.md ├── imoverlay.m ├── test_script_PST.m └── PST.m ├── Python ├── .gitignore ├── README.md ├── PST_function.py └── test_script_PST.py ├── Test_Images ├── cameraman.tif ├── cameraman_edge.tif └── cameraman_overlay.tif ├── LICENSE.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac generated files 2 | ._* 3 | # Matlab generated files 4 | *.asv 5 | *.m~ 6 | # Python generated directory 7 | __pycache__ 8 | -------------------------------------------------------------------------------- /Matlab/.gitignore: -------------------------------------------------------------------------------- 1 | # Mac generated files 2 | ._* 3 | # Matlab generated files 4 | *.asv 5 | *.m~ 6 | # Python generated directory 7 | __pycache__ 8 | -------------------------------------------------------------------------------- /Python/.gitignore: -------------------------------------------------------------------------------- 1 | # Mac generated files 2 | ._* 3 | # Matlab generated files 4 | *.asv 5 | *.m~ 6 | # Python generated directory 7 | __pycache__ 8 | -------------------------------------------------------------------------------- /Test_Images/cameraman.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JalaliLabUCLA/Image-feature-detection-using-Phase-Stretch-Transform/HEAD/Test_Images/cameraman.tif -------------------------------------------------------------------------------- /Test_Images/cameraman_edge.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JalaliLabUCLA/Image-feature-detection-using-Phase-Stretch-Transform/HEAD/Test_Images/cameraman_edge.tif -------------------------------------------------------------------------------- /Test_Images/cameraman_overlay.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JalaliLabUCLA/Image-feature-detection-using-Phase-Stretch-Transform/HEAD/Test_Images/cameraman_overlay.tif -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # License 2 | 3 | Copyright (c) 2016, Jalali Lab All rights reserved. 4 | 5 | PST function is developed in Jalali Lab at University of California, Los Angeles (UCLA). PST is a spin-off from research on the photonic time stretch technique at UCLA. More information about the technique can be found on our group website: http://www.photonics.ucla.edu 6 | 7 | The source code provided in the repository is for research purposes only. A license must be obtained from the University of California, Los Angeles for any commercial applications. The software is subject to US patent #10,275,891. 8 | 9 | -------------------------------------------------------------------------------- /Matlab/README.md: -------------------------------------------------------------------------------- 1 | ## Instructions 2 | 3 | Image processing toolbox is needed to run this function, function has been tested on MATLAB R2013a on a computer with Windows 7, 64-bit operating system. The code uses IMOVERLAY function developed by Steven L. Eddins for visualization of detected features. 4 | The test image is loaded in line #8 in the test_script_PST.m file. The test images can be called from the Test_Images directory and then, set the file name in the code on line #8. 5 | The images can be color or greyscale. However, PST operation occurs on color images only after converting them to greyscale. 6 | 7 | ## Copyright 8 | PST function using MATLAB is developed in Jalali Lab at University of California, Los Angeles (UCLA). PST is a spin-off from research on the photonic time stretch technique in Jalali lab at UCLA. More information about the technique can be found on our group website: http://www.photonics.ucla.edu 9 | 10 | This function is provided for research purposes only. A license must be obtained from the University of California, Los Angeles for any commercial applications. The software is protected under a US patent. 11 | 12 | ## Citations 13 | 1. M. H. Asghari, and B. Jalali, "Edge detection in digital images using dispersive phase stretch," International Journal of Biomedical Imaging, Vol. 2015, Article ID 687819, pp. 1-6 (2015). 14 | 2. M. H. Asghari, and B. Jalali, "Physics-inspired image edge detection," IEEE Global Signal and Information Processing Symposium (GlobalSIP 2014), paper: WdBD-L.1, Atlanta, December 2014. 15 | 3. M. Suthar, H. Asghari, and B. Jalali, "Feature Enhancement in Visually Impaired Images", IEEE Access 6 (2018): 1407-1415. 16 | 4. Y. Han, and B. Jalali, "Photonic time-stretched analog-to-digital converter: Fundamental concepts and practical considerations", Journal of Lightwave Technology 21, no. 12 (2003): 3085. 17 | # 18 | Copyright (c) 2016, Jalali Lab All rights reserved. 19 | -------------------------------------------------------------------------------- /Python/README.md: -------------------------------------------------------------------------------- 1 | # Instructions for Python 3.x 2 | 3 | ## Prerequisites 4 | You can install most of the following packages using pip. 5 | * NumPy 6 | * Python Imaging Library (PIL) 7 | * Matplotlib 8 | * Itertools 9 | * Mahotas 10 | 11 | ## Remarks 12 | Mahotas library is needed to implement morphological operations and display overlay in case of digital edge detection (if Morph_flag==1). 13 | 14 | ## Testing 15 | Put your test images in the Test_Images directory and then, set the file path in the code on line 70. You can also pass the filename using the command line [Uncomment lines 64 and 72 and comment line 70]. 16 | The images can be color or greyscale. However, PST operation occurs on color images only after converting them to greyscale. You can change the filename in the test_script_PST.py code to run the algorithm on the test image. 17 | 18 | ## Visualization 19 | The code uses matplotlib and mahouts to visualize PST edge map and overlay (in case of digital edge). [See section # Display results in test_script_PST.py] 20 | 21 | ## Test Results 22 | The PST edge map and overlay (in case of digital edge when Morph_flag==1) are saved in the Test_Images folder. [See section # Save results test_script_PST.py] 23 | 24 | ## Copyright 25 | PST function is developed in Jalali Lab at University of California, Los Angeles (UCLA). PST is a spin-off from research on the photonic time stretch technique in Jalali lab at UCLA. More information about the technique can be found on our group website: http://www.photonics.ucla.edu 26 | This function is provided for research purposes only. A license must be obtained from the University of California, Los Angeles for any commercial applications. The software is protected under a US patent. 27 | 28 | 29 | ## Citations 30 | 1. M. H. Asghari, and B. Jalali, "Edge detection in digital images using dispersive phase stretch," International Journal of Biomedical Imaging, Vol. 2015, Article ID 687819, pp. 1-6 (2015). 31 | 2. M. H. Asghari, and B. Jalali, "Physics-inspired image edge detection," IEEE Global Signal and Information Processing Symposium (GlobalSIP 2014), paper: WdBD-L.1, Atlanta, December 2014. 32 | 3. M. Suthar, H. Asghari, and B. Jalali, "Feature Enhancement in Visually Impaired Images", IEEE Access 6 (2018): 1407-1415. 33 | 4. Y. Han, and B. Jalali, "Photonic time-stretched analog-to-digital converter: Fundamental concepts and practical considerations", Journal of Lightwave Technology 21, no. 12 (2003): 3085. 34 | 35 | # 36 | Copyright (c) 2016, Jalali Lab All rights reserved. 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Image-feature-detection-using-Phase-Stretch-Transform 2 | Phase Stretch Transform (PST) is an operator that finds features 3 | in an image. PST takes an intensity image I as its input, and returns 4 | a binary image out of the same size as I, with 1's where the function 5 | finds sharp transitions in I and 0's elsewhere. PST function is also 6 | able to return the detected features in gray scale level (i.e. 7 | without thresholding). 8 | 9 | In PST, the image is first filtered by passing through a 10 | smoothing filter followed by application of a nonlinear 11 | frequency-dependent phase described by the PST phase kernel. The 12 | output of the transform is the phase in the spatial domain. The main 13 | step is the 2-D phase function (PST phase kernel) which is typically 14 | applied in the frequency domain. The amount of phase applied to the 15 | image is frequency dependent with higher amount of phase applied to 16 | higher frequency features of the image. Since sharp transitions, 17 | such as edges and corners, contain higher frequencies, PST 18 | emphasizes the edge information. Features can be further enhanced by 19 | applying thresholding and morphological operations. For more 20 | information please visit: 21 | https://en.wikipedia.org/wiki/Phase_stretch_transform 22 | 23 | ## Copyright 24 | PST function is developed in Jalali Lab at University of 25 | California, Los Angeles (UCLA). PST is a spin-off from research on 26 | the photonic time stretch technique in Jalali lab at UCLA. More 27 | information about the technique can be found on our group website: 28 | http://www.photonics.ucla.edu 29 | 30 | This function is provided for research purposes only. A license 31 | must be obtained from the University of California, Los Angeles for 32 | any commercial applications. The software is protected under a US 33 | patent. 34 | 35 | ## Citations 36 | 1. M. H. Asghari, and B. Jalali, "Edge detection in digital 37 | images using dispersive phase stretch," International Journal of 38 | Biomedical Imaging, Vol. 2015, Article ID 687819, pp. 1-6 (2015). 39 | 2. M. H. Asghari, and B. Jalali, "Physics-inspired image edge 40 | detection," IEEE Global Signal and Information Processing Symposium 41 | (GlobalSIP 2014), paper: WdBD-L.1, Atlanta, December 2014. 42 | 3. M. Suthar, H. Asghari, and B. Jalali, "Feature Enhancement in Visually 43 | Impaired Images", IEEE Access 6 (2018): 1407-1415. 44 | 4. Y. Han, and B. Jalali, "Photonic time-stretched analog-to-digital converter: 45 | Fundamental concepts and practical considerations", Journal of 46 | Lightwave Technology 21, no. 12 (2003): 3085. 47 | # 48 | Copyright (c) 2016, Jalali Lab All rights reserved. 49 | -------------------------------------------------------------------------------- /Matlab/imoverlay.m: -------------------------------------------------------------------------------- 1 | function out = imoverlay(in, mask, color) 2 | %IMOVERLAY Create a mask-based image overlay. 3 | % OUT = IMOVERLAY(IN, MASK, COLOR) takes an input image, IN, and a binary 4 | % image, MASK, and produces an output image whose pixels in the MASK 5 | % locations have the specified COLOR. 6 | % 7 | % IN should be a grayscale or an RGB image of class uint8, uint16, int16, 8 | % logical, double, or single. If IN is double or single, it should be in 9 | % the range [0, 1]. If it is not in that range, you might want to use 10 | % mat2gray to scale it into that range. 11 | % 12 | % MASK should be a two-dimensional logical matrix. 13 | % 14 | % COLOR should be a 1-by-3 vector of values in the range [0, 1]. [0 0 0] 15 | % is black, and [1 1 1] is white. 16 | % 17 | % OUT is a uint8 RGB image. 18 | % 19 | % Examples 20 | % -------- 21 | % Overlay edge detection result in green over the original image. 22 | % 23 | % I = imread('cameraman.tif'); 24 | % bw = edge(I, 'canny'); 25 | % rgb = imoverlay(I, bw, [0 1 0]); 26 | % imshow(rgb) 27 | % 28 | % Treating the output of peaks as an image, overlay the values greater than 29 | % 7 in red. The output of peaks is not in the usual grayscale image range 30 | % of [0, 1], so use mat2gray to scale it. 31 | % 32 | % I = peaks; 33 | % mask = I > 7; 34 | % rgb = imoverlay(mat2gray(I), mask, [1 0 0]); 35 | % imshow(rgb, 'InitialMagnification', 'fit') 36 | 37 | % Steven L. Eddins 38 | % Copyright 2006-2012 The MathWorks, Inc. 39 | 40 | % If the user doesn't specify the color, use white. 41 | DEFAULT_COLOR = [1 1 1]; 42 | if nargin < 3 43 | color = DEFAULT_COLOR; 44 | end 45 | 46 | % Force the 2nd input to be logical. 47 | mask = (mask ~= 0); 48 | 49 | % Make the uint8 the working data class. The output is also uint8. 50 | in_uint8 = in*1;%im2uint8(in); 51 | color_uint8 = im2uint8(color); 52 | 53 | % Initialize the red, green, and blue output channels. 54 | if ndims(in_uint8) == 2 55 | % Input is grayscale. Initialize all output channels the same. 56 | out_red = in_uint8; 57 | out_green = in_uint8; 58 | out_blue = in_uint8; 59 | else 60 | % Input is RGB truecolor. 61 | out_red = in_uint8(:,:,1); 62 | out_green = in_uint8(:,:,2); 63 | out_blue = in_uint8(:,:,3); 64 | end 65 | 66 | % Replace output channel values in the mask locations with the appropriate 67 | % color value. 68 | out_red(mask) = color_uint8(1); 69 | out_green(mask) = color_uint8(2); 70 | out_blue(mask) = color_uint8(3); 71 | 72 | % Form an RGB truecolor image by concatenating the channel matrices along 73 | % the third dimension. 74 | out = cat(3, out_red, out_green, out_blue); 75 | -------------------------------------------------------------------------------- /Matlab/test_script_PST.m: -------------------------------------------------------------------------------- 1 | % Implementation of Phase Stretch Transform (PST) in Matlab 2 | % author: M. Asghari and Madhuri Suthar, Jalali Lab, Department of Electrical and Computer Engineering, UCLA 3 | 4 | clc % clear screen 5 | clear all % clear all variables 6 | close all % close all figures 7 | 8 | % import original image 9 | filename = 'cameraman.tif'; 10 | filepath =strcat('../Test_Images/',filename); 11 | Image_orig=imread(filepath); 12 | 13 | % if image is a color image, convert it to grayscale 14 | try 15 | Image_orig=rgb2gray(Image_orig); 16 | catch 17 | end 18 | 19 | %show the original image 20 | subplot(1,2,1) 21 | imshow(Image_orig) 22 | title('Original Image') 23 | 24 | % convert the grayscale image do a 2D double array 25 | Image_orig=double(Image_orig); 26 | 27 | % low-pass filtering (also called localization) parameter 28 | handles.LPF=0.21; % Gaussian low-pass filter Full Width at Half Maximum (FWHM) (min:0 , max : 1) 29 | 30 | % PST parameters 31 | handles.Phase_strength=0.48; % PST kernel Phase Strength 32 | handles.Warp_strength=12.14; % PST Kernel Warp Strength 33 | 34 | % Thresholding parameters (for post processing) 35 | handles.Thresh_min=-1; % minimum Threshold (a number between 0 and -1) 36 | handles.Thresh_max=0.0019; % maximum Threshold (a number between 0 and 1) 37 | 38 | % choose to compute the analog or digital edge 39 | Morph_flag = 1 ; % Morph_flag=0 to compute analog edge and Morph_flag=1 to compute digital edge. 40 | 41 | % Apply PST and find features (sharp transitions) 42 | [Edge PST_Kernel]= PST(Image_orig,handles,Morph_flag); 43 | 44 | if Morph_flag ==0 45 | % show the detected features 46 | subplot(1,2,2) 47 | imshow(Edge/max(max(Edge))*3) 48 | title('Detected features using PST') 49 | % save the image 50 | file_and_extension=strsplit(filename,'.'); 51 | output_path=char(strcat('../Test_Images/',file_and_extension(1),'_edge.tif')); 52 | imwrite(Edge/max(max(Edge))*3,output_path); 53 | else 54 | subplot(1,2,2) 55 | imshow(Edge) 56 | title('Detected features using PST') 57 | % save the image 58 | file_and_extension=strsplit(filename,'.'); 59 | output_path=char(strcat('../Test_Images/',file_and_extension(1),'_edge.tif')); 60 | imwrite(Edge,output_path); 61 | % overlay original image with detected features 62 | overlay = double(imoverlay(Image_orig, Edge/1000000, [1 0 0])); 63 | figure 64 | imshow(overlay/max(max(max(overlay)))); 65 | title('Detected features using PST overlaid with original image') 66 | % save the image 67 | output_path=char(strcat('../Test_Images/',file_and_extension(1),'_overlay.tif')); 68 | imwrite(overlay/max(max(max(overlay))),output_path); 69 | end 70 | 71 | % show the PST phase kernel gradient 72 | figure 73 | [D_PST_Kernel_x D_PST_Kernel_y]=gradient(PST_Kernel); 74 | mesh(sqrt(D_PST_Kernel_x.^2+D_PST_Kernel_y.^2)) 75 | title('PST Kernel phase Gradient') 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /Python/PST_function.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Implementation of Phase Stretch Transform (PST) in Python 5 | @author: Madhuri Suthar, Ph.D. candidate, Jalali Lab, Department of Electrical and Computer Engineering, UCLA 6 | 7 | PST or Phase Stretch Transform is a physics-inspired edge detection algorithm that detects intensity variations in an image [1,2]. 8 | PST operates on an input greyscale image and outputs an edge map. The output egde map, same as the size of the input image, is binary with 9 | pixel value equal to 1 where the PST operator finds sharp transitions in intensity and 0 elsewhere. The PST operator can also return 10 | a continous level edge map (i.e. without thresholding and morphological operations) 11 | 12 | The PST operator cascades Gaussian smoothing, application of a nonlinear frequency-dependent phase kernel in frequency domain and a phase detection in spatial domain. 13 | To implement the first step, an isotropic gaussian filter with a user defined scale (LPF) is designed and operated on the image. 14 | Next, a 2D PST phase kernel is designed in frequency domain and applied to the spectrum of the input image. The output of the transform is the 15 | phase in the spatial domain. The amount of phase applied to the image is frequency dependent with higher amount of phase applied to higher frequency features of the 16 | image. Since sharp transitions, such as edges and corners, contain higher frequencies, PST emphasizes the edge information. Features can 17 | be further enhanced by applying thresholding and morphological operations. 18 | For more information please visit: https://en.wikipedia.org/wiki/Phase_stretch_transform 19 | 20 | [out PST_Kernel]= PST(Image,LPF,Phase_strength,Warp_strength, Threshold_min, Threshold_max, Morph_flag) takes the image I and applies 21 | PST phase kernel parameters are described as follows: 22 | 23 | Parameters 24 | ---------- 25 | LPF : Isotropic Gaussian localization filter Full Width at Half Maximum (FWHM) (min : 0, max : 1) 26 | Phase_strength : PST Kernel Phase Strength (min : 0, max : 1) 27 | Warp_strength : PST Kernel Warp Strength (min : 0, max : 1) 28 | Threshold_min : minimum threshold (min : -1, max : 0) 29 | Threshold_max : maximum threshold (min : 0, max : 1) 30 | Morph_flag allows user to compute the analog edge (if Morph_flag=0) or the digital edge (analog edge followed 31 | by thresholding and morphological operations, if Morph_flag=1). 32 | 33 | Copyright 34 | --------- 35 | PST function is developed in Jalali Lab at University of California, 36 | Los Angeles (UCLA). PST is a spin-off from research on the photonic time stretch technique in Jalali lab at UCLA. 37 | More information about the technique can be found in our group 38 | website: http://www.photonics.ucla.edu 39 | This function is provided for research purposes only. A license must be 40 | obtained from the University of California, Los Angeles for any commercial 41 | applications. The software is protected under a US patent. 42 | 43 | Citations 44 | --------- 45 | 1. M. H. Asghari, and B. Jalali, "Edge detection in digital images using dispersive phase stretch," International Journal of Biomedical Imaging, Vol. 2015, Article ID 687819, pp. 1-6 (2015). 46 | 2. M. H. Asghari, and B. Jalali, "Physics-inspired image edge detection," IEEE Global Signal and Information Processing Symposium (GlobalSIP 2014), paper: WdBD-L.1, Atlanta, December 2014. 47 | 3. M. Suthar, H. Asghari, and B. Jalali, "Feature Enhancement in Visually Impaired Images", IEEE Access 6 (2018): 1407-1415. 48 | 4. Y. Han, and B. Jalali, "Photonic time-stretched analog-to-digital converter: Fundamental concepts and practical considerations", Journal of Lightwave Technology 21, no. 12 (2003): 3085. 49 | """ 50 | # Imports 51 | # [] Need to install mahotas library for morphological operations 52 | import math 53 | import numpy as np 54 | import mahotas as mh 55 | 56 | # Define functions 57 | def cart2pol(x, y): 58 | theta = np.arctan2(y, x) 59 | rho = np.hypot(x, y) 60 | return (theta, rho) 61 | def PST(I,LPF,Phase_strength,Warp_strength, Threshold_min, Threshold_max, Morph_flag): 62 | L=0.5 63 | x = np.linspace(-L, L, I.shape[0]) 64 | y = np.linspace(-L, L, I.shape[1]) 65 | [X1, Y1] =(np.meshgrid(x, y)) 66 | X=X1.T 67 | Y=Y1.T 68 | [THETA,RHO] = cart2pol(X,Y) 69 | 70 | # Apply localization kernel to the original image to reduce noise 71 | Image_orig_f=((np.fft.fft2(I))) 72 | expo = np.fft.fftshift(np.exp(-np.power((np.divide(RHO, math.sqrt((LPF**2)/np.log(2)))),2))) 73 | Image_orig_filtered=np.real(np.fft.ifft2((np.multiply(Image_orig_f,expo)))) 74 | # Constructing the PST Kernel 75 | PST_Kernel_1=np.multiply(np.dot(RHO,Warp_strength), np.arctan(np.dot(RHO,Warp_strength)))-0.5*np.log(1+np.power(np.dot(RHO,Warp_strength),2)) 76 | PST_Kernel=PST_Kernel_1/np.max(PST_Kernel_1)*Phase_strength 77 | # Apply the PST Kernel 78 | temp=np.multiply(np.fft.fftshift(np.exp(-1j*PST_Kernel)),np.fft.fft2(Image_orig_filtered)) 79 | Image_orig_filtered_PST=np.fft.ifft2(temp) 80 | 81 | # Calculate phase of the transformed image 82 | PHI_features=np.angle(Image_orig_filtered_PST) 83 | 84 | if Morph_flag ==0: 85 | out=PHI_features 86 | else: 87 | # find image sharp transitions by thresholding the phase 88 | features = np.zeros((PHI_features.shape[0],PHI_features.shape[1])) 89 | features[PHI_features> Threshold_max] = 1 # Bi-threshold decision 90 | features[PHI_features< Threshold_min] = 1 # as the output phase has both positive and negative values 91 | features[I<(np.amax(I)/20)]=0 # Removing edges in the very dark areas of the image (noise) 92 | 93 | # apply binary morphological operations to clean the transformed image 94 | out = features 95 | out = mh.thin(out, 1) 96 | out = mh.bwperim(out, 4) 97 | out = mh.thin(out, 1) 98 | out = mh.erode(out, np.ones((1, 1))); 99 | 100 | return (out, PST_Kernel) 101 | -------------------------------------------------------------------------------- /Matlab/PST.m: -------------------------------------------------------------------------------- 1 | % Implementation of Phase Stretch Transform (PST) in Matlab 2 | % author: M. Asghari, Jalali Lab, Department of Electrical and Computer Engineering, UCLA 3 | function [out PST_Kernel]= PST(I,handles,Morph_flag) 4 | %PST or Phase Stretch Transform is an operator that finds features in an 5 | % image. PST takes an intensity image I as its input, and returns a 6 | % binary image out of the same size as I, with 1's where the function finds sharp transitions in 7 | % I and 0's elsewhere. PST function is also able to return the detected features in gray scale 8 | % level (i.e. without thresholding). 9 | % 10 | % In PST, the image is first filtered by passing through a smoothing 11 | % filter followed by application of a nonlinear frequency-dependent phase 12 | % described by the PST phase kernel. The output of the transform is the 13 | % phase in the spatial domain. The main step is the 2-D phase function 14 | % (PST phase kernel) which is typically applied in the frequency domain. 15 | % The amount of phase applied to the image is frequency dependent with 16 | % higher amount of phase applied to higher frequency features of the 17 | % image. Since sharp transitions, such as edges and corners, contain 18 | % higher frequencies, PST emphasizes the edge information. Features can 19 | % be further enhanced by applying thresholding and morphological operations. 20 | % For more information please visit: https://en.wikipedia.org/wiki/Phase_stretch_transform 21 | % 22 | % [out PST_Kernel]= PST(I,handles, Morph_flag) takes the original image I and applies 23 | % PST to it. PST kernel paramters are given using a handle variable: 24 | % 25 | % handles.LPF : Gaussian low-pass filter Full Width at Half Maximum (FWHM) (min : 0, max : 1) 26 | % handles.Phase_strength : PST kernel Phase Strength (min : 0, max : 1) 27 | % handles.Warp_strength : PST Kernel Warp Strength (min : 0, max : 1) 28 | % handles.Thresh_min : minimum Threshold (min : -1, max : 0) 29 | % handles.Thresh_max : maximum Threshold (min : 0, max : 1) 30 | % 31 | % Morph_flag allows user to compute the analog edge (if Morph_flag=0) or the digital edge (analog edge followed 32 | % by thresholding and morphological operations)(if Morph_flag=1). 33 | % 34 | % Class Support 35 | % ------------- 36 | % I is a double precision 2D array. out is of class logical. 37 | % 38 | % Remarks 39 | % ------- 40 | % image processing toolbox is needed to run this function, function has 41 | % been tested on MATLAB R2013a on a computer with Windows 7, 64 bits operating sytsem. 42 | % The code uses IMOVERLAY function deveopled by Steven L. Eddins for visulaization of detected features. 43 | % 44 | % Example 45 | % ------- 46 | % Example 1: Find the features of the circuit.tif image using PST method: 47 | % 48 | % I = imread('circuit.tif'); 49 | % I=double(I); 50 | % handles.LPF=0.21; 51 | % handles.Phase_strength=0.48; 52 | % handles.Warp_strength=12.14; 53 | % handles.Thresh_min=-1; 54 | % handles.Thresh_max=0.004; 55 | % [out PST_Kernel]= PST(I,handles); 56 | % figure, imshow(out) 57 | % 58 | % Example 2: Find the features in the Lena image. See the attached test script. 59 | % 60 | % Copyright 61 | % --------- 62 | % PST function is developed in Jalali Lab at University of California, 63 | % Los Angeles (UCLA). PST is a spin-off from research on the photonic time stretch technique in Jalali lab at UCLA. 64 | % More information about the technique can be found in our group 65 | % website: http://www.photonics.ucla.edu 66 | % This function is provided for research purposes only. A license must be 67 | % obtained from the University of California, Los Angeles for any commercial 68 | % applications. The software is protected under a US patent. 69 | % Citations: 70 | % 1. M. H. Asghari, and B. Jalali, "Edge detection in digital images using dispersive phase stretch," International Journal of Biomedical Imaging, Vol. 2015, Article ID 687819, pp. 1-6 (2015). 71 | % 2. M. H. Asghari, and B. Jalali, "Physics-inspired image edge detection," IEEE Global Signal and Information Processing Symposium (GlobalSIP 2014), paper: WdBD-L.1, Atlanta, December 2014. 72 | % 3. M. Suthar, H. Asghari, and B. Jalali, "Feature Enhancement in Visually Impaired Images", IEEE Access 6 (2018): 1407-1415. 73 | % 4. Y. Han, and B. Jalali, "Photonic time-stretched analog-to-digital converter: Fundamental concepts and practical considerations", Journal of Lightwave Technology 21, no. 12 (2003): 3085. 74 | % Copyright 1992-2016 The MathWorks, Inc. 75 | % $Revision: 0.0.0.1 $ $Date: 2016/02/09 13:20:56 $ 76 | 77 | % define two dimentional cartesian (rectangular) vectors, X and Y 78 | Image_orig_size=size(I); 79 | L=0.5; 80 | x=linspace(-L,L,Image_orig_size(1)); 81 | y=linspace(-L,L,Image_orig_size(2)); 82 | [X,Y]=ndgrid(x,y); 83 | 84 | % Convert cartesian X and Y vectors to polar vectors, THETA and RHO 85 | [THETA,RHO] = cart2pol(X,Y); 86 | 87 | % define two dimentional cartesian frequency vectors, FX and FY 88 | X_step=x(2)-x(1); 89 | fx=linspace(-0.5/X_step,0.5/X_step,length(x)); 90 | fx_step=fx(2)-fx(1); 91 | Y_step=y(2)-y(1); 92 | fy=linspace(-0.5/Y_step,0.5/Y_step,length(y)); 93 | fy_step=fy(2)-fy(1); 94 | [FX,FY]=ndgrid(fx,fy); 95 | 96 | % Convert cartesian vectors (FX and FY) to polar vectors, FTHETA and FRHO 97 | [FTHETA,FRHO] = cart2pol(FX,FY); 98 | 99 | % low pass filter the original image to reduce noise 100 | Image_orig_f=((fft2(I))); 101 | sigma=(handles.LPF)^2/log(2); 102 | Image_orig_f=Image_orig_f.*fftshift(exp(-(RHO/sqrt(sigma)).^2)); 103 | Image_orig_filtered=real(ifft2((Image_orig_f))); 104 | 105 | % Constrcut the PST Kernel 106 | PST_Kernel=(RHO*handles.Warp_strength.*atan(RHO*handles.Warp_strength)-0.5*log(1+(RHO*handles.Warp_strength).^2)); 107 | PST_Kernel=PST_Kernel/max(max(PST_Kernel))*handles.Phase_strength; 108 | 109 | % Apply the PST Kernel 110 | temp=(fft2(Image_orig_filtered)).*fftshift(exp(-1j*PST_Kernel)); 111 | Image_orig_filtered_PST=ifft2(temp); 112 | 113 | % Calculate phase of the transformed image 114 | PHI_features=angle(Image_orig_filtered_PST); 115 | 116 | if Morph_flag ==0 117 | out=PHI_features; 118 | else 119 | % find image sharp transitions by thresholding the phase 120 | features=zeros(size(PHI_features)); 121 | features(find(PHI_features>handles.Thresh_max))=1; 122 | features(find(PHI_features