How to accurately select the colored areas in the image?

What are you trying to achieve?:

I want to select colored areas accurately in these images(here are example),and these images have some overlapping parts.

actually two images here

What did you try to make it work?:

I think I need to add code to achieve.AI give me one idea,Controlling mouse selection through pixels.Let the mouse skip the transparent area when selecting,and select according to the pixel color.

When you say “selecting”, what do you mean? Do you mean accepting mouse clicks only in the selected area?

If you’ve got a coordinate on screen and want to know what colour the pixels underneath is, you could use
win._getPixels([<pixels from left of window>, <pixels from bottom of window>, 1, 1]). If you’ve got your coordinate from a mouse click, you’ll likely need to do some transformation to convert it from whatever units you’re using to being in pixels and from the bottom left of the screen rather than the middle. So you could use this approach to get the colour of the pixel a mouse click is on and choose whether to accept it or not based on that, if that’s what you mean?

1 Like

Hello!Two areas have different pattern,before show two areas,user will see a legend.So user should choose an area that is consistent with the pattern in the legend.

Ah I see, so you want to register clicks on only a specific area inside an image. That’s tricky - what you essentially need to do is generate a set of vertices for the shape you want, from there you can make a transparent Polygon :polygon: Component with those vertices and have that be the allowed stimulus for your Mouse :mouse: Component instead. Generating those vertices is the hard part however.

There is a demo which lets you draw a shape using your mouse and then gives you the vertices you drew at the end, so if you’re okay with just a rough outline then you could generate vertices for each shape and point to them in the same conditions file as defines your image stim?

Hello!I understand your soultion.

Can a set of vertices produce smooth curve?And can I define relative position(Accurate coordinate position) between each vertice?

Enough vertices at a shallow enough angle can, yes. That’s difficult if you’re drawing by hand but if you can generate them mathematically (possibly by the same method you’re creating these stimuli?) then you can absolutely make curves.

You can also do relative positioning, yes. Vertices of a shape are defined relative to the size and position of the shape, and the maths to convert those to the units of the window are done by the isPressedIn function (so handled by the :mouse: Mouse Component)