i using this code to make (text) image segmentation
#include <cv.h>
#include <highgui.h>
#include <cvaux.h>
#include <stdio.h>
const char *WIN1="Segmented";
IplImage* imagen;
IplImage* imagen_color;
IplImage* smooth;
IplImage* threshold;
IplImage* open_morf;
IplImage* blobResult;
IplImage* img_contornos;
CvMoments moments;
CvHuMoments humoments;
CvSeq* contour;
CvSeq* contourLow;
int main()
{
char* filename= "C:\\Users\\Mostafa\\Desktop\\Untitled.jpg";
imagen = cvLoadImage(filename,0);
imagen_color = cvLoadImage(filename,1);
smooth= cvCreateImage(cvSize(imagen->width, imagen->height), IPL_DEPTH_8U, 1);
threshold= cvCreateImage(cvSize(imagen->width, imagen->height), IPL_DEPTH_8U, 1);
open_morf= cvCreateImage(cvSize(imagen->width, imagen->height), IPL_DEPTH_8U, 1);
contour = 0;
contourLow = 0;
CvMemStorage* storage = cvCreateMemStorage(0);
cvNamedWindow(WIN1);
cvSmooth(imagen, smooth, CV_GAUSSIAN, 3, 0, 0, 0);
CvScalar avg;
CvScalar avgStd;
cvAvgSdv(smooth, &avg, &avgStd, NULL);
cvThreshold(smooth, threshold, (int)avg.val[0]-7*(int)(avgStd.val[0]/8), 255, CV_THRESH_TOZERO_INV);
cvErode(threshold, open_morf, NULL,1);
cvDilate(open_morf, open_morf, NULL,1);
img_contornos = cvCloneImage(open_morf);
cvFindContours( img_contornos, storage, &contour, sizeof(CvContour),
CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0) );
contourLow=cvApproxPoly(contour, sizeof(CvContour), storage,CV_POLY_APPROX_DP,1,1);
for( ; contourLow != 0; contourLow = contourLow->h_next )
{
CvScalar color = CV_RGB( rand()&200, rand()&200, rand()&200 );
cvDrawContours( imagen_color, contourLow, color, color, -1, 0, 8, cvPoint(0,0) );
CvRect rect;
CvPoint pt1, pt2;
rect=cvBoundingRect(contourLow, NULL);
pt1.x = rect.x;
pt2.x = (rect.x+rect.width);
pt1.y = rect.y;
pt2.y = (rect.y+rect.height);
cvRectangle(imagen_color, pt1,pt2, color, 1, 8, 0);
cvMoments(contourLow, &moments, 0);
cvGetHuMoments(&moments, &humoments);
}
cvShowImage(WIN1, imagen_color);
cvWaitKey(0);
cvDestroyWindow(WIN1);
return 0;
}
but when i run this code didn't make segmentation to the dark background image
or colored background image
any help in this code
Thanks .