Android Question Read color of the first pixel of a figure.

vecino

Well-Known Member
Licensed User
Longtime User
Hello, I am given images with regular and irregular polygons, limited by black lines.
The pixel furthest to the left and above each cell has a color.
The user touches a "box" / cell and I must know what color is the top / left pixel of that cell.
Can you give me an idea to start with?
This is an example of an image and in each box there is a pixel of a color that I must read, it is always the top / left pixel of each box / cell.
Thank you.

ejemplo3.png
 

Sandman

Expert
Licensed User
Longtime User
It would seem to me that there are many polygons that don't have an obvious pixel that can be considered in a top left position. Can you express what pixel you want in another way that makes it generic enough to work for all polygons?

(I'm taking the liberty of assuming that you're not working with complex polygons.)
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hi, thanks for your response.
I will better explain what I need.
They give me some drawings/images that are made up of multiple polygons that can be regular or irregular. They are usually squares and rectangles, although not always.
Their borders are all delimited with black lines.
These drawings and those polygons are locations.
What I need exactly is to identify which polygon the user has clicked on.
Sure there is a safe way to do it, it occurred to me to put a pixel of a different color in each polygon/location.
The background color of the polygons can be the same or different.
I'm just trying to find a way to identify them separately when the user clicks on them.
Thank you.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Thanks for the explanation. In that case I imagine there are many better ways of solving the problem, depending on your situation.

Is this correct?
- You get bitmaps with polygons
- You have no access to the exact coordinates used to create the bitmaps
- You can ask them to make a pixel in each polygon in another color (to use as an identifier)

Thoughts:
- If you have actual polygon coordinates instead of images things will most likely be a lot easier for you.
- If you can ask them to id each polygon by a single pixel, you can also do so by colouring the whole polygon (doesn't mean the end user has to see lots of different colours).

Question:
- What is the max number of possible polygons in a bitmap?
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
These polygons are drawings made by users of shelves, holes, cabinets, boxes, etc. where they locate objects.
They are small warehouses that want to know where the objects are located.
The problem is that they are not regular shelves, rather they are quite irregular, drawers, holes, etc. as I said before.
Usually they send me a simple drawing on paper and I have to start from that drawing to create something "well done" to put in the application.
That's all they send me, although sometimes, instead of a drawing on paper, they send me a few photos taken with the phone so that I can draw from those photos.
Therefore, I am in charge of "making the drawing beautiful and functional" to be able to use it in the application and to know where the user has clicked.
They are usually small warehouses, the maximum number of polygons I think will never reach 100.
Thanks again.

Here I attach a couple of drawings that have been sent to me and that I have to leave them "operational" to introduce them in the application.
 

Attachments

  • ej1.png
    ej1.png
    3 KB · Views: 156
  • ej2.png
    ej2.png
    1.2 KB · Views: 147
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
I can paint each polygon in one color and then it would be easy to identify them. But it's going to look like a color palette or a child's drawing with so many colors.
That's why my idea of painting a single pixel of a different color in each polygon. I can't think of anything else.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I can paint each polygon in one color and then it would be easy to identify them.
That is a good plan.

But it's going to look like a color palette or a child's drawing with so many colors.
And that's a bad assumption. :)

Having each polygon be a unique color doesn't have to look like this:
1600064125895.png


It can look like this:
1600063965864.png

(Go ahead and check it in an image editor. Each polygon has a unique gray, ranging from #808080 to #80808a.)


Two more thoughts:

1. It might actually be a good idea to use the color palette solution, some of your customers might be interested in color coding their locations in the warehouses. In addition, they could perhaps pick the desired colour themselves, and for extra money you could send them a printout of the color that they can physically put on the shelves.

2. If the grayscale version has too much variation, perhaps you could use a gif instead. That's why I asked how many polygons you could have. Consider the fact that a gif works with indexed colours. Each colour can look the same, while still having a unique index that can be used to id it. (A gif can hold 256 (or perhaps 255, I forget) colours, so if you max out at 100 this is a possible solution also.)

Hope this helps
 
Upvote 0

JeffT

Member
Licensed User
One way to do 'which polygon have I clicked upon' is to maintain two images.
One is your wireframe.
The other, same size, offscreen, is the one that

DOES look like this..
1600064125895.png



When a user taps on the wire frame version, go get the color from the bright color version.
Now you know exactly which one was picked, just by looking at the color
 
Upvote 0

emexes

Expert
Licensed User
Another trap is that edge pixels can unexpectedly change color, thanks to things like resizing (resampling), subpixel rendering and antialiasing.

Clarification: edge as in of a region or line, not just the outer edges of the image.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Yep, but the example pictures didn't have that so I excluded that obstacle from my suggestion.
I was referring to edge pixels, not solid-color-area pixels (and the hijacking of low-order bits, which solution you beat me to ✌).

The flexibility and generality of JeffT's two-image solution trumps us both, though, I think. ?
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thanks friends, you have given me some great ideas and advice to keep in mind.
I'm going to try it out, to see which one suits me best.
Thanks again.
:)
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I thought about adopting the method of putting "almost equal" colors to polygons, but some customers want one color, other customers want another color, etc.
So I have implemented the method of having two images, each customer will have their image as they like, and without it being seen, I will have the image with colors, so there will be no problems for them or for me.
Thank you very much.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Right, now customers can give me any image they want.
With that method, I don't care what they want, it's great.
Thank you.
 
Upvote 0
Top