Masking in codes

58 views
Skip to first unread message

Mahdi Bazargani

unread,
Nov 3, 2014, 3:54:00 AM11/3/14
to jfeat...@googlegroups.com
Dear Jfeaturelib users,

I am trying to apply the codes for masking on some filtres using jfeture lib but I amnot sure how to code them using the mask images

for below codes I amusing Harlik

        File f = new File(test.class.getResource("/IMD088.bmp").toURI());
        ColorProcessor image = new ColorProcessor(ImageIO.read(f));

        // Haralick
        Haralick descriptor = new Haralick();
        descriptor.run(image);
        List<double[]> features = descriptor.getFeatures();

        for (double[] feature : features) {
            System.out.println(Arrays2.join(feature, ", ", "%.5f"));


Can someone point me how to add a masking image so thus harlik feature are applied on masking areas idntfied by my mask image file (I have a black and white mask file)

Regards,

Franz Graf

unread,
Nov 3, 2014, 7:19:03 AM11/3/14
to jfeat...@googlegroups.com
Hi Mahdi,

in https://github.com/locked-fg/JFeatureLib/blob/master/src/main/java/de/lmu/ifi/dbs/jfeaturelib/features/Haralick.java
you can see that Haralick currently does not support masking out of
the box.

you could of course copy the image, whiten/blacken the according area
and then extract the features - but this will of course have impact to
some of the calculated features :-/ (that's why I haven't implemented
masking yet).

Regards Franz
> --
> You received this message because you are subscribed to the Google Groups
> "JFeatureLib" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jfeaturelib...@googlegroups.com.
> To post to this group, send email to jfeat...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Website: http://www.Locked.de
Google+: https://plus.google.com/u/0/107945158062341260943
Xing: https://www.xing.com/profile/Franz_Graf4

Franz Graf

unread,
Nov 3, 2014, 7:20:19 AM11/3/14
to jfeat...@googlegroups.com
Oh just forgot - maybe you can just extract a minimum bounding image
from the mask and cut the image accordingly. I dare say this is better
than blackening/whitening the image.

Cheers Franz

Luckyluke

unread,
Nov 3, 2014, 11:53:29 PM11/3/14
to jfeat...@googlegroups.com
Hi Thanks for your reply,

Actually I dont need a boxing mask rather my masking images are identfied by arbitrary black and white areas.

I wonder you have used masking using images in intelligent codes in wiki but it can not be using programming?

==

foo/
   /
images/foo.jpg
   
/images/bar.jpg
   
/masks/foo.png   <-- will match /images/foo.jpg
   
/masks/x/bar.png <-- will *not* match as there is no /images/x/bar.*
==

Can you help me in codes whats is the best way or alternative ways to do it using codes? I am new to this package so dont have any idea about your altrenatives.

Thanks

Franz Graf

unread,
Nov 4, 2014, 2:20:16 PM11/4/14
to jfeat...@googlegroups.com
Hi,

well some algorithms are easier portable to support masking than others.

Haralick itself isn't that compilcated, that's true. But if you have a
look at the implementation it's not that easy to "just" plug in masking.

I currently see the following solutions to the problem:

- you dive into the the implementation and add the necessary code. This
is most complicated but fame and glory will be yours if you contribute
some code
- you compute a bounding box around the visible part of the image and
blacken/whiten the mask in the image. By cropping to the bounding box
you can limit the effect near the borders. But you will some (hard to
quantify) impact to the feature vectors. This can be done directly by
using ImageJ before handing it to JFeatureLib.

Sorry that there is no convenient solution in the Haralick-Case.

Regards
Franz
> --
> You received this message because you are subscribed to the Google
> Groups "JFeatureLib" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jfeaturelib...@googlegroups.com
> <mailto:jfeaturelib...@googlegroups.com>.
> To post to this group, send email to jfeat...@googlegroups.com
> <mailto:jfeat...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--
Dr. Franz Graf
Homepage: http://www.Locked.de
G+: https://plus.google.com/+FranzGraf

Luckyluke

unread,
Nov 5, 2014, 12:40:05 AM11/5/14
to jfeat...@googlegroups.com
Ok thanks, I am not specific on harlick but what about other features (such as Histogram) which support masking.

I actually want to extract most feature for an image classification system.

Franz Graf

unread,
Nov 5, 2014, 1:10:14 AM11/5/14
to jfeat...@googlegroups.com
Hi,

Okay so you do not want to know how to apply masking via the commandline (
https://code.google.com/p/jfeaturelib/wiki/Howtos ) but how to call the Extractor in your own Java program?

Just have a look at https://code.google.com/p/jfeaturelib/source/browse/src/main/java/de/lmu/ifi/dbs/jfeaturelib/utils/Extractor.java
The run method of the inner class ExtractionTask describes what you need.

Hope this helps.

Good luck
Franz
Dr. Franz Graf
http://www.Locked.de

Luckyluke

unread,
Nov 8, 2014, 6:20:01 AM11/8/14
to jfeat...@googlegroups.com
Dear Franz,

I am doing the below codes for Hostogram descriptor 

=============
   File f = new File(Test.class.getResource("/IMD002.bmp").toURI());
        File f1 = new File(Test.class.getResource("/IMD002_R1_Label4.bmp").toURI());
        ColorProcessor image = new ColorProcessor(ImageIO.read(f));
        ColorProcessor mask = new ColorProcessor(ImageIO.read(f1));
        
        image.setMask(mask);

        // initialize the descriptor
        //Haralick descriptor = new Haralick();
        
        LibProperties prop = LibProperties.get();
        prop.setProperty(LibProperties.HISTOGRAMS_BINS, 2);
        prop.setProperty(LibProperties.HISTOGRAMS_TYPE, "Red");
        
        
        
        Histogram descriptor1 = new Histogram();
        descriptor1.setProperties(prop);
        

        // run the descriptor and extract the features
        descriptor1.run(image);

        // obtain the features
        List<double[]> features = descriptor1.getFeatures();
        
        System.out.println(descriptor1.getDescription());
        // print the features to system out
        for (double[] feature : features) {
            System.out.println(Arrays2.join(feature, ", ", "%.5f"));
            
        }
==============

But I get cast exception when I run the histogram descriptor.

Exception in thread "main" java.lang.ClassCastException: [I cannot be cast to [B
at de.lmu.ifi.dbs.jfeaturelib.features.Histogram.getHistogram(Histogram.java:197)
at de.lmu.ifi.dbs.jfeaturelib.features.Histogram.getHistogram(Histogram.java:151)
at de.lmu.ifi.dbs.jfeaturelib.features.Histogram.access$400(Histogram.java:44)
at de.lmu.ifi.dbs.jfeaturelib.features.Histogram$RgbMix.run(Histogram.java:266)
at de.lmu.ifi.dbs.jfeaturelib.features.Histogram.run(Histogram.java:91)


Can you help fix the above exception?

Thanks

Franz Graf

unread,
Nov 8, 2014, 8:34:55 AM11/8/14
to jfeat...@googlegroups.com
Hi,

the mask must be a binary mask (either visible or not). Just change
ColorProcessor mask = new ColorProcessor(ImageIO.read(f1));
to
ByteProcessor mask = new ByteProcessor(ImageIO.read(f1));
A local test worked.

I'll fix it in the mean time.

Thanks for reporting.

Franz
> --
> You received this message because you are subscribed to the Google
> Groups "JFeatureLib" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jfeaturelib...@googlegroups.com
> <mailto:jfeaturelib...@googlegroups.com>.

Luckyluke

unread,
Nov 13, 2014, 7:30:56 AM11/13/14
to jfeat...@googlegroups.com
Hi Franz,

I recived exception for above codes
            
===========
Exception in thread "main" java.lang.IllegalArgumentException: Type!=TYPE_BYTE_GRAYY
at ij.process.ByteProcessor.<init>(ByteProcessor.java:77)
at Test.main(Test.java:31)
===========

however,I changed to grayscale such as below then I guess is working properly..




        File f = new File(Test.class.getResource("/IMD002.bmp").toURI());
        File f1 = new File(Test.class.getResource("/IMD002_R1_Label4.bmp").toURI());
        ColorProcessor image = new ColorProcessor(ImageIO.read(f));
        //ByteProcessor mask = new ByteProcessor(ImageIO.read(f1));
        ColorProcessor maskI=new ColorProcessor(ImageIO.read(f1));
        ImagePlus imP=new ImagePlus("tt",maskI); 
        
        IJ.run(imP,"8-bit", "");
        
        image.setMask(imP.getChannelProcessor());

        // initialize the descriptor
        //Haralick descriptor = new Haralick();
        
        LibProperties prop = LibProperties.get();
        prop.setProperty(LibProperties.HISTOGRAMS_BINS, 2);
        prop.setProperty(LibProperties.HISTOGRAMS_TYPE, "Red");
        
        
        
        Histogram descriptor1 = new Histogram();
        descriptor1.setProperties(prop);
        

        // run the descriptor and extract the features
        descriptor1.run(image);

        // obtain the features
        List<double[]> features = descriptor1.getFeatures();
        
        System.out.println(descriptor1.getDescription());
        // print the features to system out
        for (double[] feature : features) {
            System.out.println(Arrays2.join(feature, ", ", "%.5f"));
            
        }

Regards

Luckyluke

unread,
Nov 26, 2014, 4:55:09 AM11/26/14
to jfeat...@googlegroups.com
Hi Franz,

I have two other questions

1-How to get which features support masking?

2- How to get the exact feature names in java codes as they are obtained by below line
List<double[]> features = descriptor1.getFeatures();

Thanks if you answer above questions..

Franz Graf

unread,
Nov 29, 2014, 7:38:23 AM11/29/14
to jfeat...@googlegroups.com
HI,

on https://code.google.com/p/jfeaturelib/wiki/FeaturesOverview you can
find the docs for this. Just use --list-capabilities to list information
about the descriptors:

> java -cp JFeatureLib-x.x.x-jar-with-dependencies.jar de.lmu.ifi.dbs.jfeaturelib.utils.Extractor --list-capabilities

What do you mean by the feature names? you mean the name of arry
position 1, 2, 3 etc? Currently there is no such information.

FeatureDescriptor#getDescription() could be also what you're looking for:
https://github.com/locked-fg/JFeatureLib/blob/master/src/main/java/de/lmu/ifi/dbs/jfeaturelib/features/FeatureDescriptor.java

Regards

Franz
> > <mailto:jfeaturelib...@googlegroups.com>.
> > To post to this group, send email to jfeat...@googlegroups.com
> > <mailto:jfeat...@googlegroups.com>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> Dr. Franz Graf
> Homepage: http://www.Locked.de
> G+: https://plus.google.com/+FranzGraf
> <https://plus.google.com/+FranzGraf>
>
> --
> You received this message because you are subscribed to the Google
> Groups "JFeatureLib" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to jfeaturelib...@googlegroups.com
> <mailto:jfeaturelib...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages