Reusing Make Binary and Skeletonize methods

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reusing Make Binary and Skeletonize methods

hector.longarte
Hello Imagers,
I need help with this: I need to use the plugins of imageJ in my
application  with the command for Make binary:

*IJ.runPlugin(imp,"ij.plugin.Thresholder", "Make Binary");*

And skeletize it...
*IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Skeletonize");    *

But the image I get appears noised all times,may be I am missing some
parameter?

I am copying here the classes I am writting ..
If someone can help me I will send the image of the check to personal mail
because this list does not accept attached files ...

Thank you very much if someone may help me..

*Class for the preprocessing:*

package com;
import ij.IJ;
import ij.ImagePlus;
import java.awt.image.BufferedImage;

public class Preprocessing {

    //  Binarizacion...
   public BufferedImage umbralizarFirma(BufferedImage firma) {
        ImagePlus imp;
        imp = new ImagePlus("firmaOriginal", firma);
        IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Make Binary");
        BufferedImage bf = (BufferedImage) imp.getImage();
        return bf;
    }
    //  Skeletonize...
    public BufferedImage skeletonFirma(BufferedImage firma) {
        ImagePlus imp;
        imp = new ImagePlus("firmaOriginal", firma);
        IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Skeletonize");
        BufferedImage bf = (BufferedImage) imp.getImage();
        return bf;
    }
}
------------------------------
----------------------------------------------------------
*Main class:*
package com;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import com.Preprocessing;

public class Director {
    private BufferedImage imagen;

    //Constructors...
    public Director(String imagen) throws Exception {
        this.imagen = ImageIO.read(new File(imagen));
    }
    public Director() { }


    // Write image to disk...
    public void guardarImagen(String nombreResultado) {
        try {
            ImageIO.write(imagen, "jpg", new File(nombreResultado));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws Exception {

        // Load the check and cut the signature...
        Director imagenCheque = new Director("c:/chequeAnverso.bmp");

        Director imagenFirma = new Director();
        System.out.println("*** Recortando desde el pixel 370,138 ...");

        imagenFirma.imagen = imagenCheque.imagen.getSubimage(370, 138,322,
135);
        imagenFirma.guardarImagen("c:/firma5.bmp");

        // Binarize the signature...
        Preprocessing binarize = new Preprocessing();
        imagenFirma.imagen = binarize.umbralizarFirma(imagenFirma.imagen);
        imagenFirma.guardarImagen("c:/firmaBinarizada5.bmp");
        System.out.println("*** Firma binarizada...");

        // Skeletonize the signature...
        imagenFirma.imagen = binarize.skeletonFirma(imagenFirma.imagen);
        imagenFirma.guardarImagen("c:/firmaSkeleton5.bmp");
        System.out.println("*** Firma skeletionized...");
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: Reusing Make Binary and Skeletonize methods

Wayne Rasband
On Dec 12, 2008, at 9:11 AM, Hector Longarte wrote:

> Hello Imagers,
> I need help with this: I need to use the plugins of imageJ in my
> application  with the command for Make binary:
>
> *IJ.runPlugin(imp,"ij.plugin.Thresholder", "Make Binary");*
>
> And skeletize it...
> *IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Skeletonize");    *
>
> But the image I get appears noised all times,may be I am missing some
> parameter?

The only parameter used by the "Make Binary" and "Skeletonize" commands
is the "Black Background" flag that is set in the
Process>Binary>Options dialog box. Run this code

    Prefs.blackBackground = true;
    IJ.run(imp, "Make Binary", "");
    IJ.run(imp, "Skeletonize", "");

and the image ('imp') and will be converted to an 8-bit image with a
white skeleton on a black background. Run this code

    Prefs.blackBackground = false;
    IJ.run(imp, "Make Binary", "");
    IJ.run(imp, "Skeletonize", "");

and you will get a black skeleton on a white background. In both cases
the background will be zero, but the image with a white background will
have in inverting lookup table.

-wayne

>
> I am copying here the classes I am writting ..
> If someone can help me I will send the image of the check to personal
> mail
> because this list does not accept attached files ...
>
> Thank you very much if someone may help me..
>
> *Class for the preprocessing:*
>
> package com;
> import ij.IJ;
> import ij.ImagePlus;
> import java.awt.image.BufferedImage;
>
> public class Preprocessing {
>
>     //  Binarizacion...
>    public BufferedImage umbralizarFirma(BufferedImage firma) {
>         ImagePlus imp;
>         imp = new ImagePlus("firmaOriginal", firma);
>         IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Make Binary");
>         BufferedImage bf = (BufferedImage) imp.getImage();
>         return bf;
>     }
>     //  Skeletonize...
>     public BufferedImage skeletonFirma(BufferedImage firma) {
>         ImagePlus imp;
>         imp = new ImagePlus("firmaOriginal", firma);
>         IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Skeletonize");
>         BufferedImage bf = (BufferedImage) imp.getImage();
>         return bf;
>     }
> }
> ------------------------------
> ----------------------------------------------------------
> *Main class:*
> package com;
> import java.awt.image.BufferedImage;
> import java.io.File;
> import javax.imageio.ImageIO;
> import com.Preprocessing;
>
> public class Director {
>     private BufferedImage imagen;
>
>     //Constructors...
>     public Director(String imagen) throws Exception {
>         this.imagen = ImageIO.read(new File(imagen));
>     }
>     public Director() { }
>
>
>     // Write image to disk...
>     public void guardarImagen(String nombreResultado) {
>         try {
>             ImageIO.write(imagen, "jpg", new File(nombreResultado));
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
>
>     public static void main(String[] args) throws Exception {
>
>         // Load the check and cut the signature...
>         Director imagenCheque = new Director("c:/chequeAnverso.bmp");
>
>         Director imagenFirma = new Director();
>         System.out.println("*** Recortando desde el pixel 370,138
> ...");
>
>         imagenFirma.imagen = imagenCheque.imagen.getSubimage(370,
> 138,322,
> 135);
>         imagenFirma.guardarImagen("c:/firma5.bmp");
>
>         // Binarize the signature...
>         Preprocessing binarize = new Preprocessing();
>         imagenFirma.imagen =
> binarize.umbralizarFirma(imagenFirma.imagen);
>         imagenFirma.guardarImagen("c:/firmaBinarizada5.bmp");
>         System.out.println("*** Firma binarizada...");
>
>         // Skeletonize the signature...
>         imagenFirma.imagen =
> binarize.skeletonFirma(imagenFirma.imagen);
>         imagenFirma.guardarImagen("c:/firmaSkeleton5.bmp");
>         System.out.println("*** Firma skeletionized...");
>     }
> }
>
Reply | Threaded
Open this post in threaded view
|

Re: Reusing Make Binary and Skeletonize methods

hector.longarte
Thanks for the response Wayne,

After I run the command I catched the image as BufferedIamge but this Image
is noised and has no significant signature. I dont know what is wrong...

// This method binarizes the signature...
    public BufferedImage umbralizarFirma(BufferedImage firma) {
        Prefs.blackBackground = false;
        ImagePlus imp;
        imp = new ImagePlus("firmaOriginal", firma);
        IJ.runPlugIn(imp,"Make Binary","");
        BufferedImage bf = (BufferedImage) imp.getImage();
        return bf;
    }

Could you please give your mail so I can send the check image to you and
then you run the code as I do to figure out what is wrong?
Thank you very much
Best regards
Hector Longarte



2008/12/12 Wayne Rasband <[hidden email]>

> On Dec 12, 2008, at 9:11 AM, Hector Longarte wrote:
>
>  Hello Imagers,
>> I need help with this: I need to use the plugins of imageJ in my
>> application  with the command for Make binary:
>>
>> *IJ.runPlugin(imp,"ij.plugin.Thresholder", "Make Binary");*
>>
>> And skeletize it...
>> *IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Skeletonize");    *
>>
>> But the image I get appears noised all times,may be I am missing some
>> parameter?
>>
>
> The only parameter used by the "Make Binary" and "Skeletonize" commands is
> the "Black Background" flag that is set in the Process>Binary>Options dialog
> box. Run this code
>
>   Prefs.blackBackground = true;
>   IJ.run(imp, "Make Binary", "");
>   IJ.run(imp, "Skeletonize", "");
>
> and the image ('imp') and will be converted to an 8-bit image with a white
> skeleton on a black background. Run this code
>
>   Prefs.blackBackground = false;
>   IJ.run(imp, "Make Binary", "");
>   IJ.run(imp, "Skeletonize", "");
>
> and you will get a black skeleton on a white background. In both cases the
> background will be zero, but the image with a white background will have in
> inverting lookup table.
>
> -wayne
>
>
>
>> I am copying here the classes I am writting ..
>> If someone can help me I will send the image of the check to personal mail
>> because this list does not accept attached files ...
>>
>> Thank you very much if someone may help me..
>>
>> *Class for the preprocessing:*
>>
>> package com;
>> import ij.IJ;
>> import ij.ImagePlus;
>> import java.awt.image.BufferedImage;
>>
>> public class Preprocessing {
>>
>>    //  Binarizacion...
>>   public BufferedImage umbralizarFirma(BufferedImage firma) {
>>        ImagePlus imp;
>>        imp = new ImagePlus("firmaOriginal", firma);
>>        IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Make Binary");
>>        BufferedImage bf = (BufferedImage) imp.getImage();
>>        return bf;
>>    }
>>    //  Skeletonize...
>>    public BufferedImage skeletonFirma(BufferedImage firma) {
>>        ImagePlus imp;
>>        imp = new ImagePlus("firmaOriginal", firma);
>>        IJ.runPlugIn(imp,"ij.plugin.filter.Binary", "Skeletonize");
>>        BufferedImage bf = (BufferedImage) imp.getImage();
>>        return bf;
>>    }
>> }
>> ------------------------------
>> ----------------------------------------------------------
>> *Main class:*
>> package com;
>> import java.awt.image.BufferedImage;
>> import java.io.File;
>> import javax.imageio.ImageIO;
>> import com.Preprocessing;
>>
>> public class Director {
>>    private BufferedImage imagen;
>>
>>    //Constructors...
>>    public Director(String imagen) throws Exception {
>>        this.imagen = ImageIO.read(new File(imagen));
>>    }
>>    public Director() { }
>>
>>
>>    // Write image to disk...
>>    public void guardarImagen(String nombreResultado) {
>>        try {
>>            ImageIO.write(imagen, "jpg", new File(nombreResultado));
>>        } catch (Exception e) {
>>            e.printStackTrace();
>>        }
>>    }
>>
>>    public static void main(String[] args) throws Exception {
>>
>>        // Load the check and cut the signature...
>>        Director imagenCheque = new Director("c:/chequeAnverso.bmp");
>>
>>        Director imagenFirma = new Director();
>>        System.out.println("*** Recortando desde el pixel 370,138 ...");
>>
>>        imagenFirma.imagen = imagenCheque.imagen.getSubimage(370, 138,322,
>> 135);
>>        imagenFirma.guardarImagen("c:/firma5.bmp");
>>
>>        // Binarize the signature...
>>        Preprocessing binarize = new Preprocessing();
>>        imagenFirma.imagen = binarize.umbralizarFirma(imagenFirma.imagen);
>>        imagenFirma.guardarImagen("c:/firmaBinarizada5.bmp");
>>        System.out.println("*** Firma binarizada...");
>>
>>        // Skeletonize the signature...
>>        imagenFirma.imagen = binarize.skeletonFirma(imagenFirma.imagen);
>>        imagenFirma.guardarImagen("c:/firmaSkeleton5.bmp");
>>        System.out.println("*** Firma skeletionized...");
>>    }
>> }
>>
>>


--
Hector Longarte