RGB changing B value affects R and G as well.... How to solve?

asked 2019-03-16 17:58:34 -0500

Nabhan gravatar image

I am creating a 100x100 BufferedImage, if I set R=200, G=160, B=80.. SetRGB and Write to disc using ImageIO.write, I am getting a Solid Color image alright. I can also Get the Pixel Values of the Created Image from another function without any error.

Now, I am creating another Image with the same procedure, this time I am keeping R=200, G=160.. same as above, not disturbing. But I am changing the value of blue with an integer array, say (156, 145, 24.......). I expect an Image With Red and Green Constant as the previous Image, different values for Blue. But Using my reader function to GetPixels, I have 2 problems i) Blue, is NOT retrieving the Values that I set ii) Instead being constant, R and G values are also some random(?) numbers.. (The Writer or Reader functions do not throw any errors). I am working with Java, OpenCV 2+ version, Netbeans. Any Idea what could be wrong? Thanks in advance.

edit retag flag offensive close merge delete

Comments

we need your code, to see what you're doing. could you please edit your question, and edit the relevant part there ?

berak gravatar imageberak ( 2019-03-17 02:04:15 -0500 )edit

btw, BufferedImage, SetRGB, GetPixels -- none of it opencv code, so how would that be relevant here ?

berak gravatar imageberak ( 2019-03-17 02:49:12 -0500 )edit

If you are saving the image as a JPG or other lossy format, you could be seeing compression artifacts that result in R and G value changes. What do you mean by R and G being random values? Are they close to 200,160, but they vary by 1 or 2 levels, or do they vary a lot? Also is it possible that you are saving in one format and retrieving in another? (something as simple as RGB/BGR, or mayy RGB/YUV)

swebb_denver gravatar imageswebb_denver ( 2019-03-17 10:11:06 -0500 )edit
1

How you assign the value of blue by array? May this is the problem, and also, which flag you use during the creation of the image? CV_8U? An example code to reproduce the error is more than appreciate

HYPEREGO gravatar imageHYPEREGO ( 2019-03-18 06:10:53 -0500 )edit