Trying to combine two images

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Trying to combine two images

Schwab,Wilhelm K
Are there any good examples of using a mask to highlight portions of an image?  I have an onion-skin effect in mind, but could live with almost anything that is easy to see and does not obliterate the underlying image.  The goal is to paint a mask that will select irregular regions of an image.

If I have a black and white mask, I can use #eraseShape: and #reverse to get two separate images, and I appear to be able to make the masked portion of one of them transpaent and can (not terribly well) highlight the masked portion of the other.  Things quickly sprial down hill when I try to combine the two pieces.  Any pointers would be appreciatiated.

Bill


Reply | Threaded
Open this post in threaded view
|

Re: Trying to combine two images

Andreas.Raab
On 8/6/2010 6:22 PM, Schwab,Wilhelm K wrote:
> Are there any good examples of using a mask to highlight portions of an image?  I have an onion-skin effect in mind, but could live with almost anything that is easy to see and does not obliterate the underlying image.  The goal is to paint a mask that will select irregular regions of an image.
>
> If I have a black and white mask, I can use #eraseShape: and #reverse to get two separate images, and I appear to be able to make the masked portion of one of them transpaent and can (not terribly well) highlight the masked portion of the other.  Things quickly sprial down hill when I try to combine the two pieces.  Any pointers would be appreciatiated.
>
> Bill

Try this for starters:

        maskForm := Form dotOfSize: 400.
        (BitBlt toForm: Display)
                sourceForm: maskForm;
                destX: 100; destY: 100;
                colorMap: (WordArray with: 16rC0FFFFFF with: 0);
                combinationRule: Form blend;
                copyBits.

This will fill the exterior of the dot (to fill the interior just flip
the order of colors in the color map) directly on the target. If you
don't want (or can't) use simple alpha, then use mask with a bitOr: rule
to clear the uncovered areas. Here is the same example with a
screen-door effect instead of alpha-blending:

        maskForm := Form dotOfSize: 400.
        alphaForm := Form extent: maskForm extent depth: 8.
        "Fill alphaForm with the desired pattern"
        (alphaForm getCanvas)
                fillRectangle: alphaForm boundingBox
                color: (Color white alpha: 0.5).
        "Now mask out the area we don't want"
        (BitBlt toForm: alphaForm)
                sourceForm: maskForm;
                colorMap: (WordArray with: 16rFFFFFFFF with: 0);
                combinationRule: Form and;
                copyBits.
        alphaForm displayOn: Display at: 100@100 rule: Form paint.

And of course, if your mask is alpha to begin with, this can be heavily
simplified.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

RE: Trying to combine two images

Schwab,Wilhelm K
In reply to this post by Schwab,Wilhelm K
Andreas,

The effect from your examples was very subtle on my display, but it looked promising so I started hacking it into my code.  The results were initially very strange, but I had been badly mangling the bitblt on my end.  Things went from weird to simply ugly and I started comparing the types of forms.  I was using ColorForm, so I switched that to Form (interestingly I had only recently started using ColorForm) and the results are now really nice.

I am curious what you meant about simplifying things if my mask were alpha.  AFAIK, I am perfectly willing to use it.  What would stop me?

Thanks!!

Bill