Skip to content
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

Open
maxbrito opened this issue Feb 11, 2016 · 15 comments
Open

Java or C edition? #1

maxbrito opened this issue Feb 11, 2016 · 15 comments

Comments

@maxbrito
Copy link

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

@csachs
Copy link

csachs commented Feb 12, 2016

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,
Christian

@maxbrito
Copy link
Author

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.

@JalaliLabUCLA
Copy link
Owner

We will release the Java version soon, but we recommend to play with the MATLAB code to understand the technique.
The algorithm is patented, so for educational purposes you can use the algorithm but to use it in a commercial application, you need to obtain license from UCLA.

@maxbrito
Copy link
Author

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.

@roj4s
Copy link

roj4s commented Feb 13, 2016

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#

@JalaliLabUCLA
Copy link
Owner

Thank you for contributing. We will release the Java code soon, no need for using MATLAB's Compiler.

@maddin200
Copy link

Do you plan a C or C++ version ?

@JalaliLabUCLA
Copy link
Owner

If there is a lot of interest, we will make the c++.

@evanjbowling
Copy link

You might want to figure out whether it needs to be C++, or just something
a bit more accessible without matlab. I bet that a Python implementation
would be easier to create and would likely suffice for most research
applications. That being said, the more implementations the better!

Regards,
Evan

On Wednesday, February 17, 2016, JalaliLabUCLA [email protected]
wrote:

If there is a lot of interest, we will make the c++.


Reply to this email directly or view it on GitHub
#1 (comment)
.

@maddin200
Copy link

The idea here is to make a version using OpenCV.

@roj4s
Copy link

roj4s commented Feb 19, 2016

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.

@JalaliLabUCLA
Copy link
Owner

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.

@etale-cohomology
Copy link

I'm also very interested in a C++ (or C) port.

@amirmasoudabdol
Copy link

amirmasoudabdol commented Jun 13, 2016

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.

@JalaliLabUCLA
Copy link
Owner

We wanted to inform everyone that the Python code has been released along with the updated Matlab code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants