-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java or C edition? #1
Comments
Hello @nunobrito, if you just want to test the code, you can use the freely available Octave (a MATLAB-compatible programming language). Besides, to whom it may concern, here's a Python (with NumPy) port (almost 1:1) of the code [the cleaning steps for Morph_flag=1 are left out, as they are not easily 1:1 portable]: def pst(image, lpf=0.5, phase_strength=0.5, warp_strength=0.5, thresh_min=-0.5, thresh_max=0.5, morph_flag=False):
# port of https://github.com/JalaliLabUCLA/Image-feature-detection-using-Phase-Stretch-Transform
# restrictions on usage apply, consult the original source!
import numpy
from numpy.fft import fft2, ifft2, fftshift
def cart2pol(x, y):
return numpy.arctan2(y, x), numpy.hypot(x, y)
image = image.astype(numpy.float64)
L = 0.5
x = numpy.linspace(-L, L, image.shape[1])
y = numpy.linspace(-L, L, image.shape[0])
X, Y = numpy.meshgrid(x, y)
THETA, RHO = cart2pol(X, Y)
X_step = x[1]-x[0]
Y_step = y[1]-y[0]
fx = numpy.linspace(-L/X_step, L/X_step, len(x))
fy = numpy.linspace(-L/Y_step, L/Y_step, len(y))
fx_step = fx[1]-fx[0]
fy_step = fy[1]-fy[0]
FX, FY = numpy.meshgrid(fx_step, fy_step)
FTHETA, FRHO = cart2pol(FX, FY)
# lowpass
sigma = (lpf ** 2) / numpy.log(2)
image_f = fft2(image)
image_f = image_f * fftshift(numpy.exp(-(RHO / numpy.sqrt(sigma))**2))
image_filtered = numpy.real(ifft2(image_f))
# PST kernel construction
rws = RHO*warp_strength
pst_kernel = rws * numpy.arctan(rws) - 0.5*numpy.log(1+(rws**2))
pst_kernel /= pst_kernel.max()
pst_kernel *= phase_strength
# application of the kernel, and phase calculation
image_processed = ifft2(fft2(image_filtered) * fftshift(numpy.exp(-1j * pst_kernel)))
result = numpy.angle(image_processed)
if morph_flag == False:
return result
else:
binary = numpy.zeros_like(image, dtype=bool)
binary[result > thresh_max] = 1
binary[result < thresh_min] = 1
binary[image < image.max() / 20] = 0
# the matlab version does post-processing (cleaning) here!
return binary And thanks to Dr. Asghari and Prof. Jalali for publishing this very interesting algorithm. Regards, |
Thank you Christian. Really useful, this Python code is already something easier for me to understand as a non-MATLAB user. Was looking into the license terms (it is actually what we do at triplecheck) and the code requires licensing, plus it is protected by a US patent. Does this mean that even we'd have a Java version written that it would be under the scope of this patent? It is an interesting algorithm, just not sure if we'd be able of affording it for our (humble) context. |
We will release the Java version soon, but we recommend to play with the MATLAB code to understand the technique. |
Ok, thank you. A java edition would certainly be great. Please update this thread once it is ready so that we can get an automatic notification. |
I understand that is possible to port MATLAB code to java and c by using Matlab's Compiler SDK. Some adjustments would be required in the code to provide proper outputs. http://www.mathworks.com/products/matlab-compiler-sdk/?requestedDomain=www.mathworks.com# |
Thank you for contributing. We will release the Java code soon, no need for using MATLAB's Compiler. |
Do you plan a C or C++ version ? |
If there is a lot of interest, we will make the c++. |
You might want to figure out whether it needs to be C++, or just something Regards, On Wednesday, February 17, 2016, JalaliLabUCLA [email protected]
|
The idea here is to make a version using OpenCV. |
I'm thinking about using this algorithm for image pre-processing to later apply an OCR like Tesseract. The final intention is to be included on an Android app. Actually i'm not too experienced in the topic so i wonder if i'm in the right direction. Any advice is appreciated. |
Using the algorithm in OCR applications is a good idea, please keep us updated on how it goes and let us know if we can help. |
I'm also very interested in a C++ (or C) port. |
I'm also interested in C++ version and I am willing to help. Python is nice too but for this application I think it would be quite slow. A Python wrapper on top of the C++ code would be a better solution. |
We wanted to inform everyone that the Python code has been released along with the updated Matlab code. |
Hello,
Thanks for releasing this algorithm. Would by any chance be possible to port into Java or C code that can run without MatLab?
Many thanks in advance,
Nuno
The text was updated successfully, but these errors were encountered: