Drawing on Stemmer.Cvb.Image

Is there a way of “free drawing” on an image showed on a display?
I know how to do it with System.Drawing Graphics and creating a Pen, but of course I can not use it on a Stemmer.Cvb.Image.
I am creating a mask using this method on my current display image:

private void Threshold(int valueRange)

            Stemmer.Cvb.Image mask = Stemmer.Cvb.Foundation.Threshold.RangeThreshold(FrmMain.GlobalArray.InitalImagesArray[(int)SpnCamLatch.Value].Planes[0], new ValueRange<int>(valueRange, 255));
            DisplayMask.Image = mask;

So I have an image only with 0 and 255 values. But imagine that I have some white pixels on the black area and I want to draw over them with a pen to make them black to have a “perfect shape” mask.

I am trying to use UnmanagedGraphics but no free drawing allowed, just lines, ellipses, rectangles…

Should I think about saving my current Stemmer.Cvb.Image as bitmap, open it as System.Drawing.Image to draw on it, save the modified image and open it again as Stemmer.Cvb.Image?
I can not find any kind of info about “free drawing” on a Stemmer Image.
Thank you!

@George Hi,

IF you are using WPF, then you may find what you need in the class BrushBitOverly:

Kind regards,

1 Like

Hello Mandana, thank you for your response.
I am using Forms!
I would like to do it without using Overlays, if possible.
Kind regards!

Hi @George

drawing on an image is in fact a somewhat diverse field.
The first differentiation one has to choose is whether to draw “into” the image (i. e. modifying the image content) or drawing “over” the image (i. e. drawing over the display of the image without actually modifying the image content).

The second variety is also sometimes referred to as “destructive overlay”, whereas the first one is what we have in mind when simply talking about overlays (and even there you have different options, but I’ll get to that in a minute).

For destructive overlays there are in fact a few basic functions available in the CVB.Net API via the static methods of the class Stemmer.Cvb.ImageDrawer. Capabilities here cover only the most basic items (circles, ellipse, rectangles, lines and flood fill). But keep in mind that there are other methods to affect an image’s content; for example it is possible to use the methods in Stemmer.Cvb.Foundation.Bitwise to combine mask images with images or Stemmer.Cvb.Image.CopyTo which allows you to copy segments of images into another one. Plus, there is of course always the option to directly modify the pixel data directly.

With non-destructive overlays there are again several things you can look into - but I do not think that these cover what you want (from what you wrote I think what you are really looking for are destructive overlays); just one comment: UnmanagedGraphics will not paint into the image data - it will just modify the graphical representation on the screen and as such is only one more variety of the “non-destructive overlay” theme (UnmanagedGraphics is intended only for use with the UserOverlay class that is available for use with the Stemmer.Cvb.Forms.Controls.Display object).

Looking at your original question: If your problem is that the mask is not perfect in that there are small white specs on the black area, have you tried filtering those out? If the elements you want to get rid of are small enough, then the Stemmer.Foundation.Morphology.Open method should be able to erase them without affecting the regions you are actually interested in too much:


Thank you very much Illusive, very well explained and elaborated as usual.
Have a nice day!

1 Like