4
$\begingroup$

How can I apply a mask using drawing tools(or some other custom mask) to color replace part of an image? for example the image enter image description here

Masks returned by DominantColors (via "CoverageImage") aren't quite right, I mainly want to change to color of the glow in the image but it seems like the only way to change a color is to change it globally across the image. Which is an issue because there is white on the egg, lettering and in the center of the glow.

I've looked at ImageApply but it doesn't seem to like using ColorReplace as a pure function, so I'm sort of at a loss.

I have looked at Changing color of an object in an image but that post is 8 years old now and I think there must be an easier method today. Also alot of the code there is over my head so I could use some guidance.

$\endgroup$
2
$\begingroup$

Here is how you can use your mask to apply image operations to only a part of the image:

img = Import["https://i.stack.imgur.com/ovwNY.jpg"];
mask = Import["https://i.stack.imgur.com/e15TY.png"];
ColorNegate[mask] img + ColorReplace[mask img, White -> Red]

Output

| improve this answer | |
$\endgroup$
0
$\begingroup$

I felt weird leaving this as a comment so I'm expanding it (but I'll still give you the answer). Eventually I found the most general way was via the method introduced here https://reference.wolfram.com/language/workflow/ExtractARegionFromAnImage.html

and then using some combination of ImageRecolor or/and ColorReplace.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.