Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to remove a logo from an image using C# and AForge.NET but my code which I got from open chat gpt does not compile. Please help me complete this code to remove the logo from the image

What I have tried:

<pre lang="C#">

<pre>Bitmap map = (Bitmap)pictureBox1.Image;
        //load the input image
        /*Image<Bgr, Byte> inputImage = new Image<Bgr, Byte>(map);
        //create a log mask with a path clearly defined to where the file is
        Image<Gray, Byte> mask = new Image<Gray, Byte>(inputImage.Width, inputImage.Height);
        //path to the image
        mask.SetValue(new Gray(255), new Image<Gray, Byte>("C:\\Users\\99ENT$TECH\\Pictures\\logo2.jpg"));
        Image<Bgr, Byte> outputImage = inputImage.InPaint(mask, 3);
        //assign the image to picture box 2
        */
        //convert image to gray scale;
        Grayscale grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721);
        Bitmap grayImage = grayscaleFilter.Apply(map);
        pictureBox2.Image = grayImage;
        //smoothen the image using a gaussian blur
        GaussianBlur blurFilter = new GaussianBlur(5, 11);
        Bitmap blurImage = blurFilter.Apply(grayImage);
        // Use the Canny edge detection algorithm to detect the edges in the image
        CannyEdgeDetector edgeFilter = new CannyEdgeDetector();
        Bitmap cannyFilter = edgeFilter.Apply(blurImage);
        // Find the contours in the image
        BlobCounter blobCounter = new BlobCounter();
        blobCounter.MinWidth = 10;
        blobCounter.MinHeight = 10;
        blobCounter.FilterBlobs = true;
        blobCounter.ProcessImage(blurImage);
        Blob[] blobs = blobCounter.GetObjectsInformation();

// Select the contour that corresponds to the logo
        int index = 0; // replace with the index of the contour that corresponds to the logo
        Blob blob = blobs[index];

// Create a mask for the logo
        blobCounter.ExtractBlobsImage(blurImage,blob, true);

// Invert the mask
        Invert invertFilter = new Invert();
        invertFilter.ApplyInPlace(cannyFilter);

// Remove the logo from the image by applying the mask to the original image
        ExtractChannel extractFilter = new ExtractChannel();
        Bitmap result = extractFilter.Apply(blurImage);

        pictureBox2.Image = result;





Posted
Updated 1-Jan-23 22:17pm

1 solution

Generally speaking, code from ChatGPT doesn't compile, and when it does, it doesn't work - we've seen quite a bit of it recently.

Removing logos from images is almost certainly in breach of the terms and conditions under which the image was released - which makes it malicious behavior.

We do not condone, support, or assist in the production of malicious code in any way, form, or manner. This is a professional site for professional developers.

If you want to know how to create such things, you need to visit a hacking site: but be sure to disable all firewalls and antivirus products first or they won't trust you enough to tell you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900