Ask Your Question
0

Opencv mean shift filtering // exact colors

asked 2016-09-07 03:52:15 -0500

Camillo gravatar image

updated 2016-09-07 04:22:48 -0500

I am using Opencv to posterize a picture with the function pyrMeanShiftFiltering, but i don't know how to posterize it to the exact 32 colors i need. I don't even know how to tell it that i need exactly 32 colors.

This is my code so far.

public void run(Mat image, double windowSize, double colorValue){

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    Imgproc.pyrMeanShiftFiltering(image,image,windowSize,colorValue,2,new TermCriteria(TermCriteria.MAX_ITER|TermCriteria.EPS, 50, 0.001));

    String filename = "<MYPATH>/Posterized_"+ (int)windowSize +"."+ (int)colorValue + ".jpg";
    System.out.println(String.format("Done. Writing %s", filename));
    Imgcodecs.imwrite(filename, image);
}

 public static void main (String[] args)
 {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat image = Imgcodecs.imread("<MYPATH>/Soccer.jpg");
    posterize po = new posterize();
    po.run(image,10,10);
 }

Any suggestions?

Thank you in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-07 18:59:28 -0500

Tetragramm gravatar image

Well, if you need a specific number of colors, you should probably use kmeans instead. You treat each pixel as a data point, with 32 clusters. Then each pixel is turned into the cluster center it is closest to.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-09-07 03:52:15 -0500

Seen: 196 times

Last updated: Sep 07 '16