0

First of all, I'm sorry for my English..

I'm new in OpenCV, trying to remove logos in images. I found this answer in this site --> How to use OpenCV to remove non text areas from a business card?

I follow the steps and write these codes:

int main(int argc,char** argv) {


Mat eroded,dilated,img1=imread("C:\\Users\\Buket\\Desktop\\Belgeler\\Oda Kayıt Belgesi\\OKB001.jpg");
int erosion_size = 6;   
Mat elementd = getStructuringElement(MORPH_CROSS,
                                    Size(2 * erosion_size + 1, 2 * erosion_size + 1), 
                                    Point(erosion_size, erosion_size) );
int dilation_size = 1;   
Mat elemente = getStructuringElement(MORPH_CROSS,
                                    Size(2 * dilation_size + 1, 2 * dilation_size + 1), 
                                    Point(dilation_size, dilation_size) );

Mat mask = Mat::zeros(img1.rows, img1.cols, CV_8UC1);
dilate(img1, dilated, elementd);

Mat lastimg;
int count =0;
do{
    lastimg = dilated;
    erode(dilated, lastimg, elemente);
    max(lastimg,img1);
    count++;
}while(count < 2);

Now I have an image that just logo on it:

Just logo

And this is the source image:

Original pic

In the article, there's that saying "you now have an image with ONLY the logo and no text, use this image to remove the logo". But how can i do that? I research a lot but found nothing..

Please help..

EDIT

Mat dest;

subtract(lastimg,img1,dest);
bitwise_not(dest,dest);

that function is the answer.

Community
  • 1
  • 1

1 Answers1

2

Try the following code, Hopefully it should work:

Mat img1=some_img;
Mat img2=some_img;

Mat dest;

cv::subtract(img1,img2,dest);

This performs pixelwise subtraction (img1-img2). find more details about it http://docs.opencv.org/modules/core/doc/operations_on_arrays.html

Saurav
  • 597
  • 10
  • 24
  • This won't work, it requires the images to be of the same size. – MoustafaS Jul 21 '16 at 13:11
  • 1
    the images she showed seemed to be of the same size and modified version of the same image file. if its the same size. then it will surely work. otherwise not. :) – Saurav Jul 21 '16 at 13:12
  • 1
    if the images are of different sizes, then you have to localize the area of logo, probably go with template matching or object detection or feature detection and then blankly just remove the are of logo. but for the above problem, this is probably the best solution. – Saurav Jul 21 '16 at 13:17
  • images are same size. but that doesn't work. it's output is just black picture. i want like this https://postimg.org/image/fr8r3engx/ (made by paint :) ) even so thanks for your answer – Buket Meltem Dindar Jul 21 '16 at 13:34
  • you gave "original image"-"just logo" image right?? – Saurav Jul 21 '16 at 13:38
  • can you post the respective image sizes?? i have tried the sae code for python and it works.. – Saurav Jul 21 '16 at 13:49
  • i put the parameters wrong, now it has been done! Thanks a lot! – Buket Meltem Dindar Jul 21 '16 at 13:50