1

I have several small images and I want them to have exactly 100x100 pixel without scaling. To archieve that, I'm creating a white 100x100 image and copy the small image into those.

My code:

/*Small image*/
Emgu.CV.Mat Char = new Emgu.CV.Mat();
/*...fill small Image with stuff...*/

/*Create black Image (don't know how to create a White Image)*/
FinalChar = Emgu.CV.Mat.Zeros(100, 100, Emgu.CV.CvEnum.DepthType.Cv8U, 1);

/*Invert Image to become white*/
Emgu.CV.CvInvoke.BitwiseNot(FinalChar, FinalChar);

/*Copy small Image to large Image starting at row 5 and column 5*/
Char.CopyTo(FinalChar.Row(5).Col(5)); /*This is NOT working... Image 'Finalchar' is still White.*/

Please don't tell me about this post: OpenCV draw an image over another image I don't know, but rowRange and colRange is not part of Emgu.CV.

Here is a small, not working example you can copy to try out:

            /*Create small black image*/
        Emgu.CV.Mat Small = Emgu.CV.Mat.Zeros(10, 10, Emgu.CV.CvEnum.DepthType.Cv8U, 1);

        /*Create large white image*/
        Emgu.CV.Mat Large = Emgu.CV.Mat.Zeros(20, 20, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
        Emgu.CV.CvInvoke.BitwiseNot(Large, Large);

        /*Copy small, black image to large white image at 5,5 - the large image should
         now contain a black rect in its center*/
        Small.CopyTo(Large.Row(5).Col(5));

        Emgu.CV.CvInvoke.NamedWindow("Output", Emgu.CV.CvEnum.NamedWindowType.AutoSize);
        Emgu.CV.CvInvoke.Imshow("Output", Large);
        Emgu.CV.CvInvoke.WaitKey();

        return;
Jan021981
  • 521
  • 3
  • 28
  • It would be awesome if you could provide a [mcve]. – mjwills Sep 03 '19 at 12:18
  • Possible duplicate of [Putting a smaller image within a larger image.](https://stackoverflow.com/questions/12787153/putting-a-smaller-image-within-a-larger-image) – dymanoid Sep 03 '19 at 12:22

1 Answers1

0

Ok, the example "Putting a smaller Image within a larger Image" is not correct - it just adds the Image. So it will work, if your base Image is black. But if your Image is White (R=G=B=255) and you add any value, it will Clip to 255.

But that is working for me:

    public static Emgu.CV.Mat EnterAtCenter(int Size = 100)
    {
        /*Create Mat and Image large, white*/
        Emgu.CV.Mat Large = Emgu.CV.Mat.Zeros(Size, Size, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
        Emgu.CV.CvInvoke.BitwiseNot(Large, Large);
        Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageLarge = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Large.Bitmap);

        /*Create Mat and Image small, black*/
        Emgu.CV.Mat Small = Emgu.CV.Mat.Zeros(10, 10, Emgu.CV.CvEnum.DepthType.Cv8U, 1);
        Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> ImageSmall = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(Small.Bitmap);

        /*Copy small Image to large Image at 5,5*/
        ImageLarge.ROI = new System.Drawing.Rectangle(5, 5, Small.Width, Small.Height);
        ImageSmall.CopyTo(ImageLarge);

        ImageLarge.ROI = System.Drawing.Rectangle.Empty;

        return ImageLarge.Mat;
    }
Jan021981
  • 521
  • 3
  • 28