Ask Your Question
0

What value is return when accessing a pixel from a colored image

asked 2015-07-08 11:07:21 -0600

Pure_eyse gravatar image

updated 2015-07-08 13:03:54 -0600

Hello!

Im having some problems lately about getting the color of a pixel using Open CV and java .

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat a = Imgcodecs.imread("C:\\Users\\User\\workspace\\OpenCv\\color.png",Imgcodecs.CV_LOAD_IMAGE_COLOR);
    System.out.println(Arrays.toString(getPixelColor(0, 0, a)));
    System.out.println(Arrays.toString(getPixelColor(9, 0, a)));
    System.out.println(Arrays.toString(getPixelColor(0, 9, a)));
    System.out.println(Arrays.toString(getPixelColor(9, 9, a)));

So this code returns the following

[255.0, 255.0, 0.0]
[0.0, 0.0, 255.0]
[255.0, 0.0, 0.0]
[0.0, 255.0, 255.0]

for this image image description its a 10*10 image But the right rgb color from photoshop are int that order

[0, 255.0, 255.0] Cyan
[0.0, 0.0, 255.0] Blue
[255.0, 0.0, 0.0] Red
[255.0, 255.0, 0] Yellow

The image loads up as mat from type CV_8UC3 so its rbg.

Anyone knows why is this happening ? Also if im using cvtColor to change from bgr -> rbg im not getting the right output still

[0.0, 255.0, 255.0] Cyan ok
[255.0, 0.0, 0.0] Should be blue  , is red
[0.0, 0.0, 255.0] Should be red , is blue
[255.0, 255.0, 0.0] Yellow ok
edit retag flag offensive close merge delete

Comments

can it simply be, that your getPixelColor function gets x,y wrong ?

berak gravatar imageberak ( 2015-07-09 00:20:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-07-08 11:18:18 -0600

unxnut gravatar image

Notice that your colors are in BGR order (OpenCV native) and not in RGB. Thus, [0, 255, 255] appears as [255, 255, 0]. If you really want them in RGB order, you can use cvtColor for conversion.

edit flag offensive delete link more

Comments

@unxnut That what i thought , but take the second and third color how come they are right?Also how do you convert? just swap the first and third?

Pure_eyse gravatar imagePure_eyse ( 2015-07-08 11:25:44 -0600 )edit

Your colors seem to match the BGR output. Don't know what is going on with the Photoshop output.

unxnut gravatar imageunxnut ( 2015-07-08 12:25:24 -0600 )edit

@unxnut The color are from top left -> top right -> bottom left -> bottom right. I just checked rbg of blue(top left) is 0 0 255 , just like the photoshop and not 255 0 0 as you are saying.I edited the question check it out.

Pure_eyse gravatar imagePure_eyse ( 2015-07-08 12:52:54 -0600 )edit
2

Can you check the order of parameters in your call to getPixelColor. I suspect the first parameter is row number and the second is column number but I could not find Java documentation to verify that.

unxnut gravatar imageunxnut ( 2015-07-08 18:52:26 -0600 )edit

yep that what it was

Pure_eyse gravatar imagePure_eyse ( 2015-07-09 12:42:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-08 11:06:05 -0600

Seen: 184 times

Last updated: Jul 08 '15