We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have some pictures in which have an image I want to clip surrounded in a specific color. I want to be able to leave everything inside of the color untouched and everything outside, removed - rendered transparent.
I am supposing there must be a reasonable algorithm that does this, can you point me to it, also an example of using it in processing would be great.
Answers
Do you have a real image example to show?
Well I can send an example but there is not going to be any particular similarity between any of the pictures other than there will be one color surrounding parts of the picture that I want untouched.
what I have reached on my own is that I have three states, notTriggered, Triggered, TriggerSuspended
Then I should read the image pixel for pixel left to right, at this point I start out notTriggered, so every pixel I read that is not my triggering color I make transparent. When I reach my triggering color I enter state triggered and while in state triggered I do not make pixels transparent. In order for me to reach the triggerSuspended stage I would need to read a pixel that is not my triggering color, and then after that another pixel that is my triggering color, at that point I am in triggerSuspended, the next time I read a pixel that is not my triggering color I go back to notTriggered stage and keep making pixels transparent until I again read a pixel that is my triggering color.
Obviously though there are some things that will fall through in this case so I don't think it is the right algorithm, I suppose what would be the right one would be something that first went through every pixel, found triggering colors and built up an outline of the shape that needed to be protected from being made transparent and then after this outline a second process would be started that went and made everything transparent that was not inside the outline. That I don't know how to do however.
How should I save such an algorithm (what data structure is the correct one) how do I query my data to make sure that when I am looking at any particular pixel that it is not within the outline?
Perhaps a flood fill algorithm can be used for your purpose.
Is this similar to what I've done here?: http://forum.processing.org/two/discussion/comment/516#Comment_516
Well, it is not clear since we don't have examples, but I suppose that if we have, eg. read pixels inside a blue circle, surrounded by red, only the external red pixels should become transparent, not the internal ones. At least, that's how I interpret the request, and that's why I recommended flood fill.