0
$\begingroup$

I'm making a little icon to be the default favicon in my website template. To do this I'm taking one of those dumb little globe network icons and merging it with the v11 Mathematica spikey icon. The final product looks like this:

asd

At favicon size it's not really noticeable, but it's fun anyway.

The way I'm doing this is by taking the spikey image and the globe image:

spikey =
  CloudImport[
CloudObject[
   "https://www.wolframcloud.com/objects/b3m2a1.testing/img/spikey.png"]];
baseIcon =
  CloudImport[

CloudObject[
   "https://www.wolframcloud.com/objects/b3m2a1.testing/img/globe_mask.png"]
   ];

And then merging the spikey AlphaChannel with the baseIcon and then dilating the whole mess:

baseMask =
  With[{
    chan = AlphaChannel[spikey],
    ppos = PixelValuePositions[AlphaChannel[spikey], White]
    },
   ReplacePixelValue[
    chan,
    Thread[
     ppos ->
      PixelValue[baseIcon, ppos]
     ]
    ]
   ];
mask = Dilation[newMask, 1]

mask

before finally setting that as the spikey alpha channel:

newImg = SetAlphaChannel[spikey, mask]

The problem is this is a rather slow process. PixelValuePositions is slow and can be finnicky and ReplacePixelValue is slow, too (and honestly even PixelValue can be).

So I'd rather do this with ImageAdd and ImageSubtract.

Unfortunately, neither of these really reproduce what I want when I use them by default.

Is there a good way to do this? I.e. apply an ImageAdd/ImageSubtract only to a masked part of an image?

$\endgroup$
2
$\begingroup$

Like that?

With[{alpha = AlphaChannel[spikey]}
, Dilation[
    ImageAdd[
      ImageMultiply[baseIcon, alpha ]
    , EdgeDetect @ alpha 
    ]
  , 1
  ]
]

enter image description here

$\endgroup$
  • $\begingroup$ Perfect. I knew it should have been super easy. $\endgroup$ – b3m2a1 Dec 22 '17 at 20:11

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.