Thursday, May 25, 2017

Open Source: Self-Organizing Feature Map implementation in Java


Package provides java implementation of self-organizing feature map (Kohonen map)
Build Status 


Add the following dependency to your POM file:


Image Segmentation (Clustering) using SOFM

The following sample code shows how to use SOFM to perform image segmentation:
BufferedImage img="1.jpg"));

DataFrame dataFrame = ImageDataFrameFactory.dataFrame(img);

SOFM cluster = new SOFM();;

List<Integer> classColors = new ArrayList<Integer>();
for(int i=0; i < 5; ++i){
 for(int j=0; j < 5; ++j){
    classColors.add(ImageDataFrameFactory.get_rgb(255, rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)));

BufferedImage segmented_image = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
for(int x=0; x < img.getWidth(); x++)
 for(int y=0; y < img.getHeight(); y++)
    int rgb = img.getRGB(x, y);

    DataRow tuple = ImageDataFrameFactory.getPixelTuple(dataFrame, rgb);

    int clusterIndex = cluster.transform(tuple);

    rgb = classColors.get(clusterIndex % classColors.size());

    segmented_image.setRGB(x, y, rgb);

No comments:

Post a Comment