2

I have to extract all color of image in Android without using ML (Google vision, IBM Visual Recognition).

I had check below option.

1.Palette The palette library attempts to extract the following six color profiles.

2. Get color of a particular pixel

public static int getDominantColor(Bitmap bitmap) {
Bitmap newBitmap = Bitmap.createScaledBitmap(bitmap, 1, 1, true);
final int color = newBitmap.getPixel(0, 0);
newBitmap.recycle();
return color;
}

if I break bitmap in small size then find out color and save in list. Then there is time taken and OutOfMemoryError.

Please suggest any library to find color of images.

Edit

Pick from gallary

 InputStream stream = getContentResolver().openInputStream(
                        data.getData());
                bitmap = BitmapFactory.decodeStream(stream);
                stream.close()

Get Color code from Pixel

HashMap<Integer,Integer> colorList=new HashMap<>();
private void  getAllColorInImages(Bitmap bitmap)
{
    colorList.clear();
    if(bitmap==null)
        return;
    int width=bitmap.getWidth();
    int height=bitmap.getHeight();
    for(int i=0;i<width;i++)
    {
        for(int j=0;j<height;j++)
        {
            final int color = bitmap.getPixel(i, j);
            colorList.put(color,color);

        }
    }
    System.out.println("color list size "+colorList.size());
    System.out.println("color list Name "+colorList);

}
mukesh
  • 4,140
  • 5
  • 29
  • 40
  • Do you need each and every colour used in bitmap or just one average colour of image? – Aaditya Brahmbhatt Dec 19 '18 at 05:32
  • Every color. It is use for analysis purpose. if i search a particular color in image and that color is in small part of image then we will miss in case of average – mukesh Dec 19 '18 at 05:50
  • Also, what is the exact thing you're trying to achieve? E.g. Finding number of pixels in image with some color. – Aaditya Brahmbhatt Dec 19 '18 at 05:54
  • There are certain things which are to be done using the native code, your requirement falls under that category, if you are concerned with performance and efficiency, try using OpenCV refer this [answer](https://stackoverflow.com/a/16643243/4878972) – Aseem Sharma Dec 19 '18 at 06:06
  • @AseemSharma Answer is not related to openCV and it similar to find colar and each pixel and save in list. – mukesh Dec 19 '18 at 06:15
  • @AadityaBrahmbhatt Find out all color in image or specific color exist in image – mukesh Dec 19 '18 at 06:22
  • @mukesh if you get the number of colors of each pixel then you can group them and detect available colors in the image or what? – Aseem Sharma Dec 19 '18 at 06:26
  • @AseemSharma time taken process and outofMemoryError – mukesh Dec 19 '18 at 06:43
  • Can you post your code where you get an "outofMemoryError"? This can probably be fixed – T A Dec 19 '18 at 07:56
  • @TA Not always. it is on some devices. I have edit the code. Please review it – mukesh Dec 19 '18 at 08:26
  • Calculate the histogram of the image. Colors present in the image correspond to non-zero bins. – dhanushka Dec 19 '18 at 08:35
  • I understand that you need ALL colours in bitmap but you are not realising that bitmap itself is collection of different colours! Do you want to sort colours, find most used colour etc. Also why are you storing key and value both same in your hashmap? – Aaditya Brahmbhatt Dec 20 '18 at 05:37

0 Answers0