2

these question is a follow to this one, i have an image which i want to remove logo from it, i have eroded the image until all the small text are gone away and only the logo is the remaining , now i have two images , the original image and the one with only the logo , now when i attempt to subtract the two images in order to form a third one contains only the text,a weird thing happens, the logo doesn't removed but it's outlined

code:

cv::Mat final;
cv::Mat greyMat = [self.imageView.image CVGrayscaleMat];
cv::Mat bwMat,erodedMat;
cv::threshold(greyMat, bwMat, 128, 255, CV_THRESH_BINARY);
cv::bitwise_not(bwMat, bwMat);
cv::Mat element = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(20, 12));
cv::erode(bwMat, erodedMat, element);
cv::dilate(bwMat, erodedMat, bwMat);//I used this to restore all the missed components of    the logo  during erosion,bwMat in the last argument acts as a mask, i didn't sure of this
std::vector<cv::Point>points;
cv::Mat_<uchar>::iterator it=bwMat.begin<uchar>();
cv::Mat_<uchar>::iterator end=bwMat.end<uchar>();
for (; it!=end; ++it) 
    if (*it) 
        points.push_back(it.pos());
final=bwMat-erodedMat;
Community
  • 1
  • 1
chostDevil
  • 1,041
  • 5
  • 17
  • 24

1 Answers1

1

I think this happens because when you erode an image, white area is shrinked. This erases your letters, at the same time it also shrinks area of white square.

So when you subtract, you are subtracting a shrinked square from the original square which leaves you the border.

So in this case you have to do opposite function of erosion, ie dilation. It expands the white area. It will not bring back your letters since they have already erased.

But i don't think you wont be able to completely erase the white square, since dilation will not give the exact square. You can be just better than in your question, that's all.

Check these images below. Original image:

enter image description here

Now below is the result with an erosion followed by dilation :

enter image description here

They are never the same.So when you subtract them, there will be artifacts.

I have explained another method in an answer to your first question : how to detect region of large # of white pixels using opencv?

Community
  • 1
  • 1
Abid Rahman K
  • 51,886
  • 31
  • 146
  • 157