-1

I try to convert image from RGB model to HSV and display it. Unfortunately I dont have any idea how to do this. I dont want to use built-in function but I want write function alone. I want to do this in similar way using RGB channels. I read/checked a lot of example from this site but I have not found any special and helpfull materials. Please help how should I do this.

// image from RGB to grayscale
private static BufferedImage monochromatyczny(BufferedImage obrazek)
{
    for(int x = 0; x < obrazek.getWidth(); x++)
        for(int y = 0; y < obrazek.getHeight(); y++)
        {
            int piksel = obrazek.getRGB(x, y);
            // kanały r,g,b
            int r = (piksel>>16) & 0xff;
            int g = (piksel>>8)     & 0xff;
            int b = (piksel)        & 0xff;

            int gray = (r+g+b)/3;
            piksel = (gray<<16) | (gray<<8) | gray;

            obrazek.setRGB(x,y,piksel);
        }
    return obrazek;
}
Tomek eM
  • 92
  • 1
  • 1
  • 11
  • Any reason you don't wanna use pre-made functions? – Vince Dec 01 '14 at 18:40
  • I'm doing a project with image processing and leading forbade the use of built-in functions. – Tomek eM Dec 01 '14 at 18:43
  • Thats weird, seeing how you are using a bunch of pre-made functions from the JDK such as `getRGB()`. But I guess rules are rules, no matter how weird they may seem. I'm no color expert, but [this convertor](http://www.rapidtables.com/convert/color/rgb-to-hsv.htm) shows the formula they use to convert. You could use that formula, although you're gonna have to write the code – Vince Dec 01 '14 at 18:56
  • Yes maybe it's look funny (and this what I wrote about built-in function), but I can only use "load image" and "getRGB/setRGB" (to acces to RGB channel). For example function: "rgb2gray" or "rgb2hsv" is for leading prohibited. So, rest of functions and algorytm I must create alone. "That formula" - which? If You have something helpfull please link. – Tomek eM Dec 01 '14 at 19:08
  • Just a comment: have a look at this Stackoverflow question / answer. It's for C++, but you get the idea. http://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both – geert3 Dec 01 '14 at 20:07

1 Answers1

0

Good explanation how to convert color RGB -> HSV i'm found on http://www.rapidtables.com/convert/color/rgb-to-hsv.htm

You may to try this formula in your rgb_2_hsv function

Malov Vladimir
  • 490
  • 4
  • 11