0

This is my input image:

http://www.lyndliving.com/media_library/1491/4f10819a58556504.jpg

and I would like to remove letterings from my image (Ex. DINING ROOM). How could I do this?

My code is below.

Mat skel;
Mat image=imread("InputImage4.jpg",1);
cvtColor(image,image,CV_BGR2GRAY);
threshold(image,image,50,255,THRESH_BINARY_INV);
WallFinder wall;
wall.setLineLengthAndGap(100,20);
wall.setMinVote(80);
skel=wall.skeleton(image);

Mat skeleton(Mat& img)
    {
        threshold(img, img, 50, 255, THRESH_BINARY); 
        Mat skel(img.size(), CV_8UC1, Scalar(0));
        Mat temp;
        Mat eroded;
        Mat element = getStructuringElement(MORPH_CROSS, Size(3, 3));
        bool done;      
        do
        {
          erode(img, eroded, element);
          dilate(eroded, temp, element);
          subtract(img, temp, temp);
          bitwise_or(skel, temp, skel);
          eroded.copyTo(img);
          done = (countNonZero(img) == 0);
        } while (!done);
        dilate(skel,skel,Mat(),Point(-1,-1),2);
        erode(skel,skel,Mat(),Point(-1,-1),2);
        return skel;
    }

And this my output image:

enter image description here

I must first remove letterings to do my job. (Like BATH)

1
  • So you need to do it manually ? Commented Nov 19, 2013 at 11:04

2 Answers 2

1

Use the text-detection project described here to detect the area where text is present and then simply apply the color which has the maximum occurence in your image (i.e., the background) and voila.!

HTH

Sign up to request clarification or add additional context in comments.

Comments

0

Here is a the code I made for cropping images, and made little modification to meet your requirement. And you need to manually select the area to remove.

#include <iostream>
#include "opencv2/opencv.hpp"
#include <stdio.h>

using namespace std;
using namespace cv;


Mat src,img,ROI;
Rect cropRect(0,0,0,0);
 Point P1(0,0);
 Point P2(0,0);

const char* winName="Crop Image";
bool clicked=false;
int i=0;
char imgName[15];


void checkBoundary(){
       //check croping rectangle exceed image boundary
       if(cropRect.width>img.cols-cropRect.x)
         cropRect.width=img.cols-cropRect.x;

       if(cropRect.height>img.rows-cropRect.y)
         cropRect.height=img.rows-cropRect.y;

        if(cropRect.x<0)
         cropRect.x=0;

       if(cropRect.y<0)
         cropRect.height=0;
}

void showImage(){
    img=src.clone();
    checkBoundary();
    rectangle(img, cropRect, Scalar(0,255,0), 1, 8, 0 );
    imshow(winName,img);
}


void onMouse( int event, int x, int y, int f, void* ){


    switch(event){

        case  CV_EVENT_LBUTTONDOWN  :
                                        clicked=true;

                                        P1.x=x;
                                        P1.y=y;
                                        P2.x=x;
                                        P2.y=y;
                                        break;

        case  CV_EVENT_LBUTTONUP    :
                                        P2.x=x;
                                        P2.y=y;
                                        clicked=false;
                                        break;

        case  CV_EVENT_MOUSEMOVE    :
                                        if(clicked){
                                        P2.x=x;
                                        P2.y=y;
                                        }
                                        break;

        default                     :   break;


    }


    if(clicked){
     if(P1.x>P2.x){ cropRect.x=P2.x;
                       cropRect.width=P1.x-P2.x; }
        else {         cropRect.x=P1.x;
                       cropRect.width=P2.x-P1.x; }

        if(P1.y>P2.y){ cropRect.y=P2.y;
                       cropRect.height=P1.y-P2.y; }
        else {         cropRect.y=P1.y;
                       cropRect.height=P2.y-P1.y; }

    }


showImage();


}
int main()
{

    cout<<"Click and drag for Selection"<<endl<<endl;
    cout<<"------> Press 's' to save"<<endl<<endl;
    cout<<"------> Press 'e' to reset"<<endl;
    cout<<"------> Press 'r' to reset"<<endl<<endl;
    cout<<"------> Press 'Esc' to quit"<<endl<<endl;


    src=imread("img.jpg",1);

    namedWindow(winName,WINDOW_NORMAL);
    setMouseCallback(winName,onMouse,NULL );
    imshow(winName,src);

    while(1){
    char c=waitKey();
    if(c=='s'&&ROI.data){
     sprintf(imgName,"%d.jpg",i++);
     imwrite(imgName,img);
     cout<<"  Saved "<<imgName<<endl;
    }

    if(c=='e') {
        if(cropRect.width>0&&cropRect.height>0){
        ROI=src(cropRect);
        ROI.setTo(Scalar(255,255,255));
        showImage();
       }
    }

    if(c==27) break;
    if(c=='r') {cropRect.x=0;cropRect.y=0;cropRect.width=0;cropRect.height=0;}
    showImage();

    }


    return 0;
}

Result:- enter image description here

2 Comments

Thanx so much. However I will not use mouse events. The deletion processing will be automatic.
So you should use some thing like contour finding, check for small contour, find bounding rect for each small contour, erase the region with bounding rect etc...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.