Android Question [solved] How to determine the color of a pixel, why does Photoshop give different values?

Mark Read

Well-Known Member
Licensed User
Longtime User
There is probably a simple answer for this. I am trying to get the color of the pixel marked by the two markers. This is part of my navigation program for rivers.

My program reports for the markers

Point 1 Pixel color: -1057834
Pixel Color: R255 G239 B219 O214
Point 2 Pixel color: -9199914
Pixel Color: R255 G115 B158 O214

Photoshop reports R181 G211 B206 O255 for the upper marker(1).

What is going on here please?
 

Attachments

  • Kopie von 141018095531.png
    Kopie von 141018095531.png
    343.8 KB · Views: 206

sirjo66

Well-Known Member
Licensed User
Longtime User
Please, can you tell me the X and Y coord in the image above where you get the pixels ??

Sergio
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Not really, as the original bitmap is larger as I can upload here. But you can see the two green markers with the hands. The upper one is marker 1 and the lower marker 2. The person means nothing. Both markers on on a river.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
There is probably a simple answer for this. I am trying to get the color of the pixel marked by the two markers. This is part of my navigation program for rivers.

My program reports for the markers



Photoshop reports R181 G211 B206 O255 for the upper marker(1).

What is going on here please?
O? You probably mean A (alpha channel). In Photoshop, your image is not transparent, so you get A255. In your app, the pixel that you get is very slightly transparent, so you get A214. Don't ask me why. You probably use a marker that is not totally opaque.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
@Informatix: Yes you are correct, I meant A for Alpha. The markers are the default ones in OSMDroid. But that is not really the problem. The RGB values do not match.

I want to use the RGB value to tell the difference between river and not river. Looking at the two sets of RGB values, they are very different although photoshop says they are the same. That is what I don't understand. Is this still due to the alpha value? I don't think so.

Just for info. I generate the map in OSMDroid, tap two positions, make a screenshot, save it, start a new activity, read the screenshot file into an imageview, calculate the position of the two markers and read the pixel color. The maths for the navigation can only be started when I have this problem solved.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
@Informatix: Yes you are correct, I meant A for Alpha. The markers are the default ones in OSMDroid. But that is not really the problem. The RGB values do not match.

I want to use the RGB value to tell the difference between river and not river. Looking at the two sets of RGB values, they are very different although photoshop says they are the same. That is what I don't understand. Is this still due to the alpha value? I don't think so.

Just for info. I generate the map in OSMDroid, tap two positions, make a screenshot, save it, start a new activity, read the screenshot file into an imageview, calculate the position of the two markers and read the pixel color. The maths for the navigation can only be started when I have this problem solved.
A pixel with a value < 255 for the alpha channel is blended with the color of objects behind it (e.g. with the background color of the ImageView). GetPixel returns the color of the loaded bitmap, not the color of the final result (the color that you see). If you saved a screenshot of your Activity, then there's no reason to have an alpha channel < 255 somewhere as the activity background is always opaque (unless you changed it).
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
If you saved a screenshot of your Activity, then there's no reason to have an alpha channel < 255 somewhere as the activity background is always opaque (unless you changed it).

Sorry I don't understand what you mean. I load the saved screenshot and read the two pixels, logging the results (as in post 1). I was not happy when the results were not the same. as I would have expected. Thus, I downloaded the png file from the emulator using monitor in the Android directory and looked at it in photoshop (and paintshop pro). I make no changes to the file. Photoshop reports both pixel colors as being the same! That is my problem and its driving me nuts.

Would it help if I posted the complete code?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
OK. Here is the code. I have to go out now but will be back in a few hours. Look forward to your input.
 

Attachments

  • mapview.zip
    9.2 KB · Views: 168
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
One problem I have found, in line 78 TreatBitmap, I was logging RGBA instead of ARGB for some reason. This means that the first value in res() is the alpha value -ok. But I still do not understand why the second (red) value changes when I run the program for two points on a river, 1st time gives 239 and 2nd time 189. I need a constant value for the navigation to work! The same bitmap opened in photoshop or paint shop pro gives a red value of 181 - that would be great, as no other color in the near of a river has this red value.
 
Upvote 0

nikolaus

Member
Licensed User
Longtime User
This is probably a color management problem. RGB values are relative to the devices color range. Photoshop by default applies AdobeRGB color range as target and assumes sRGB if no profile information is present in the file. This conversion changes RGB values.

Turn off profile management in PS or - better - use a stupid imaging software for that task. Paint should give you dumb RGB values without any color management applied :)
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
@nikolaus: Thanks for your input. OK ps might do that and obviously Paint shop pro from Jasc software does the same. I could live with that. But my problem of the two sets of values are not the same and they should be. The colors are the same, ps and paint shop confirm this. I can only assume I have a mistake in my code. :(
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
There is probably a simple answer for this.

How true and the answer was in the code. A simple mistake and I hold my head in shame. The pixel information generated WAS correct but was not the points I thought.

I forgot that the pixels start in the top left corner and calculated for the bottom left!:oops:

Changing line 48 in TreatBitmap from

B4X:
y1=(Main.FirstPointLat-Main.NordValues(2))*Main.ActHeight/T2B

to

B4X:
y1=Main.ActHeight-((Main.FirstPointLat-Main.NordValues(2))*Main.ActHeight/T2B)

gives the correct result.

The log now shows for two points on the river:

Point 1:549,197
Point 1 Pixel color: -4862002
Pixel Color: A255 R181 G207 B206
Point 2:768,738
Point 2 Pixel color: -4862002
Pixel Color: A255 R181 G207 B206

Now the red value for both markers agrees with photoshop and paint shop pro [181]!

Happy again :D

Thanks to all who tried to help.
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
Yeahhhhhhh, I am happy that you have solved !
I have supposed this problem, as you can read in my post #2

;)
 
Upvote 0
Top