Usage of the Erosion Plugin

59 views
Skip to first unread message

Stefan Schraß

unread,
Sep 28, 2012, 6:21:04 AM9/28/12
to marvin-...@googlegroups.com
Hi there,

I want to erode an image. But I apparently don't use the plugin the right way.

I've loaded the plugin and tried to set the attribut "matrix" with an Boolean[3][3] all "true".

int structuringElementSize = 3;
Boolean[][] structuringElement = new Boolean[structuringElementSize][structuringElementSize];
for (int i = 0; i < structuringElementSize; i++){
    for (int j = 0; j < structuringElementSize; j++) {
        structuringElement[i][j] = true;
    }
}


MarvinImagePlugin.setAttributes("matrix", structuringElement);

But I get an
java.lang.ClassCastException: [[Ljava.lang.Boolean; cannot be cast to [[Z
at org.marvinproject.image.morphological.erosion.Erosion.process(Erosion.java:30)


And I can't figure out what I am doing wrong. So any help is welcome.

Stefan Schraß

unread,
Sep 28, 2012, 6:27:40 AM9/28/12
to marvin-...@googlegroups.com
figured it out... silly mistake.

Boolean != boolean, since Boolean is an Object and boolean a primitive type. Therefore the cast failed.

Gabriel Archanjo

unread,
Sep 28, 2012, 7:26:47 AM9/28/12
to marvin-...@googlegroups.com
Hi,


Another tip! You can declare a 3x3 matrix in this way:

boolean[][] matrix_3x3 = new boolean[][] {
{true,true,true},
{true,true,true},
{true,true,true}
};

 Do not forget to convert your MarvinImage to the binary format before using morphological plug-ins. Use MarvinColorModelConverter for this purpose: http://marvinproject.sourceforge.net/javadoc/marvin/image/MarvinColorModelConverter.html


Kind regards,
Gabriel
Reply all
Reply to author
Forward
0 new messages