Exemplo n.º 1
0
Mat computeInterest(Mat& img){
	std::vector<cv::Mat> cmyk;
	rgb2cmyk(img, cmyk);
	int otsuT = getThreshVal_Otsu_8u(cmyk.at(2));
	Mat out;
	threshold(cmyk.at(2),out,otsuT,255,THRESH_BINARY);
	return img;
}
Exemplo n.º 2
0
void FillSimulation(vector <Mat> fillRegions, vector<Scalar> colorValue, vector<StrokeCluster> &fisrtDrawCluster){
	float size = 0;
	int gap = 15;
	int lineWidth = 10;
	
	//Filling regions
	for (int i = 0; i < fillRegions.size(); i++) {
		// Boundary initialization
		int ys = 1;
		int ye = fillRegions[i].rows - 1;
		int xs = 1;
		int xe = fillRegions[i].cols - 1;
		Mat fillRgionBlack;
		cvtColor(fillRegions[i], fillRgionBlack, CV_RGB2GRAY);
		fillRgionBlack = fillRgionBlack > 245;
		ofstream outputFile;
		string fileName = outputFileName("drawPoints/fill", i, ".txt");
		outputFile.open(fileName);
		Point previousPoint;
		Vec3b fillColor = Vec3b(colorValue[i][0], colorValue[i][1], colorValue[i][2]);
		Vec4f cmyk;
		rgb2cmyk(fillColor, cmyk);
		// Write indexing of color
		outputFile << (int)fillColor[0] << " " << (int)fillColor[1] << " " << (int)fillColor[2] << endl;
		outputFile << (float)cmyk[0] << " " << (float)cmyk[1] << " " << (float)cmyk[2] <<" " << (float)cmyk[3] << endl;

		// Find draw points
		for (int j = ys; j <= ye; j = j + gap)
			FindDrawPoints(j, xs, ys, xe, fillRgionBlack, outputFile, size, fillColor, cmyk, lineWidth, fisrtDrawCluster[i]);
		// Last Row
		for (int k = xs; k <= xe; k = k + gap)
			FindDrawPoints(ye, k, ys, xe, fillRgionBlack, outputFile, size, fillColor, cmyk, lineWidth, fisrtDrawCluster[i]);
		outputFile.close();
	}
	cout << "\nTotal Number of fill lines: " << fillLines << endl << endl;
}
Exemplo n.º 3
0
void colorxlate(char *str, color_t *color, color_type target_type)
{
	static hsbcolor_t	*last;
	hsbcolor_t	fake;
	char		canon[SMALLBUF];
	char		*p, *q, ch;
	double		H,S,V,R,G,B;
	double		C,M,Y,K;
	int		r,g,b,a;
	int		i;

	color->type = target_type;

	/* skip over any leading whitespace */
	for (; *str == ' '; str++);
    p = str;

	/* test for rgb value such as: "#ff0000" or rgba value such as "#ff000080" */
	a = 255; /* default alpha channel value in case not supplied */
	if ((*p == '#') && (sscanf(p,"#%2x%2x%2x%2x",&r,&g,&b,&a) >= 3)) {
		switch (target_type) {
		case HSV_DOUBLE:
			R = (double)r/255.0;
			G = (double)g/255.0;
			B = (double)b/255.0;
			rgb2hsv(R,G,B,&H,&S,&V);
			color->u.HSV[0] = H;
			color->u.HSV[1] = S;
			color->u.HSV[2] = V;
			break;
		case RGBA_BYTE:
			color->u.rgba[0] = r;
			color->u.rgba[1] = g;
			color->u.rgba[2] = b;
			color->u.rgba[3] = a;
			break;
		case CMYK_BYTE:
			R = (double)r/255.0;
			G = (double)g/255.0;
			B = (double)b/255.0;
			rgb2cmyk(R,G,B,&C,&M,&Y,&K);
			color->u.cmyk[0] = (int)C*255;
			color->u.cmyk[1] = (int)M*255;
			color->u.cmyk[2] = (int)Y*255;
			color->u.cmyk[3] = (int)K*255;
			break;
		case RGBA_WORD:
			color->u.rrggbbaa[0] = r*65535/255;
			color->u.rrggbbaa[1] = g*65535/255;
			color->u.rrggbbaa[2] = b*65535/255;
			color->u.rrggbbaa[3] = a*65535/255;
			break;
		}
		/* color->type = target_type; */
		return; 
	}

	/* test for hsv value such as: ".6,.5,.3" */
    if (((ch = *p) == '.') || isdigit(ch)) {
	    q = canon;
	    i = SMALLBUF;
	    while ((ch = *p++) && (--i)) {
            if (ch == ',') ch = ' ';
	        *q++ = ch;
	    }
        if (ch) agerr (AGWARN, "color value '%s' truncated\n", str);
	    *q = '\0';
    
	    if (sscanf(canon,"%lf%lf%lf",&H,&S,&V) == 3) {
		    /* clip to reasonable values */
		    H = MAX(MIN(H,1.0),0.0);
		    S = MAX(MIN(S,1.0),0.0);
		    V = MAX(MIN(V,1.0),0.0);
		    switch (target_type) {
		    case HSV_DOUBLE:
			    color->u.HSV[0] = H;
			    color->u.HSV[1] = S;
			    color->u.HSV[2] = V;
			    break;
		    case RGBA_BYTE:
			    hsv2rgb(H,S,V,&R,&G,&B);
			    color->u.rgba[0] = (int)(R*255);
			    color->u.rgba[1] = (int)(G*255);
			    color->u.rgba[2] = (int)(B*255);
			    color->u.rgba[3] = 255;
			    break;
		    case CMYK_BYTE:
			    hsv2rgb(H,S,V,&R,&G,&B);
			    rgb2cmyk(R,G,B,&C,&M,&Y,&K);
			    color->u.cmyk[0] = (int)C*255;
			    color->u.cmyk[1] = (int)M*255;
			    color->u.cmyk[2] = (int)Y*255;
			    color->u.cmyk[3] = (int)K*255;
			    break;
		    case RGBA_WORD:
			    hsv2rgb(H,S,V,&R,&G,&B);
			    color->u.rrggbbaa[0] = (int)(R*65535);
			    color->u.rrggbbaa[1] = (int)(G*65535);
			    color->u.rrggbbaa[2] = (int)(B*65535);
			    color->u.rrggbbaa[3] = 65535;
			    break;
		    }
		/* color->type = target_type; */
		    return;
	    }
	}

	/* test for known color name */
	fake.name = canontoken(str);
	if ((last == NULL)
	  ||(last->name[0] != fake.name[0])
	  ||(strcmp(last->name,fake.name))) {
		last = (hsbcolor_t*) bsearch((void*)&fake,
				(void*)color_lib,
				sizeof(color_lib)/sizeof(hsbcolor_t),
				sizeof(fake),(bsearch_cmpf)colorcmpf);
	}
	if (last != NULL) {
		switch (target_type) {
		case HSV_DOUBLE:
			color->u.HSV[0] = ((double)last->h)/255.0;
			color->u.HSV[1] = ((double)last->s)/255.0;
			color->u.HSV[2] = ((double)last->b)/255.0;
			break;
		case RGBA_BYTE:
			H = (last->h)/255.0;
			S = (last->s)/255.0;
			V = (last->b)/255.0;
			hsv2rgb(H,S,V,&R,&G,&B);
			color->u.rgba[0] = (int)(R*255);
			color->u.rgba[1] = (int)(G*255);
			color->u.rgba[2] = (int)(B*255);
			color->u.rgba[3] = 255;
			break;
		case CMYK_BYTE:
			H = (last->h)/255.0;
			S = (last->s)/255.0;
			V = (last->b)/255.0;
			hsv2rgb(H,S,V,&R,&G,&B);
			rgb2cmyk(R,G,B,&C,&M,&Y,&K);
			color->u.cmyk[0] = (int)C*255;
			color->u.cmyk[1] = (int)M*255;
			color->u.cmyk[2] = (int)Y*255;
			color->u.cmyk[3] = (int)K*255;
			break;
		case RGBA_WORD:
			H = (last->h)/255.0;
			S = (last->s)/255.0;
			V = (last->b)/255.0;
			hsv2rgb(H,S,V,&R,&G,&B);
			color->u.rrggbbaa[0] = (int)(R*65535);
			color->u.rrggbbaa[1] = (int)(G*65535);
			color->u.rrggbbaa[2] = (int)(B*65535);
			color->u.rrggbbaa[3] = 65535;
			break;
		}
		/* color->type = target_type; */
		return;
	}

	/* if we're still here then we failed to find a valid color spec */
	agerr (AGWARN, "%s is not a known color. Using black.\n",str);
	switch (target_type) {
	case HSV_DOUBLE:
		color->u.HSV[0] =
		       	color->u.HSV[1] =
		       	color->u.HSV[2] = 0.0;
		break;
	case RGBA_BYTE:
		color->u.rgba[0] =
		       	color->u.rgba[1] =
		       	color->u.rgba[2] = 0;
		color->u.rgba[3] = 255;
		break;
	case CMYK_BYTE:
		color->u.cmyk[0] = 
			color->u.cmyk[1] = 
			color->u.cmyk[2] = 
			color->u.cmyk[3] = 0;
		break;
	case RGBA_WORD:
		color->u.rrggbbaa[0] =
		       	color->u.rrggbbaa[1] =
		       	color->u.rrggbbaa[2] = 0;
		color->u.rrggbbaa[3] = 65535;
		break;
	}
	/* color->type = target_type; */
	return;
}
Exemplo n.º 4
0
int colorxlate(char *str, gvcolor_t * color, color_type_t target_type)
{
    static hsvrgbacolor_t *last;
    static unsigned char *canon;
    static int allocated;
    unsigned char *p, *q;
    hsvrgbacolor_t fake;
    unsigned char c;
    double H, S, V, A, R, G, B;
    double C, M, Y, K;
    unsigned int r, g, b, a;
    int len, rc;

    color->type = target_type;

    rc = COLOR_OK;
    for (; *str == ' '; str++);	/* skip over any leading whitespace */
    p = (unsigned char *) str;

    /* test for rgb value such as: "#ff0000"
       or rgba value such as "#ff000080" */
    a = 255;			/* default alpha channel value=opaque in case not supplied */
    if ((*p == '#')
	&& (sscanf((char *) p, "#%2x%2x%2x%2x", &r, &g, &b, &a) >= 3)) {
	switch (target_type) {
	case HSVA_DOUBLE:
	    R = (double) r / 255.0;
	    G = (double) g / 255.0;
	    B = (double) b / 255.0;
	    A = (double) a / 255.0;
	    rgb2hsv(R, G, B, &H, &S, &V);
	    color->u.HSVA[0] = H;
	    color->u.HSVA[1] = S;
	    color->u.HSVA[2] = V;
	    color->u.HSVA[3] = A;
	    break;
	case RGBA_BYTE:
	    color->u.rgba[0] = r;
	    color->u.rgba[1] = g;
	    color->u.rgba[2] = b;
	    color->u.rgba[3] = a;
	    break;
	case CMYK_BYTE:
	    R = (double) r / 255.0;
	    G = (double) g / 255.0;
	    B = (double) b / 255.0;
	    rgb2cmyk(R, G, B, &C, &M, &Y, &K);
	    color->u.cmyk[0] = (int) C *255;
	    color->u.cmyk[1] = (int) M *255;
	    color->u.cmyk[2] = (int) Y *255;
	    color->u.cmyk[3] = (int) K *255;
	    break;
	case RGBA_WORD:
	    color->u.rrggbbaa[0] = r * 65535 / 255;
	    color->u.rrggbbaa[1] = g * 65535 / 255;
	    color->u.rrggbbaa[2] = b * 65535 / 255;
	    color->u.rrggbbaa[3] = a * 65535 / 255;
	    break;
	case RGBA_DOUBLE:
	    color->u.RGBA[0] = (double) r / 255.0;
	    color->u.RGBA[1] = (double) g / 255.0;
	    color->u.RGBA[2] = (double) b / 255.0;
	    color->u.RGBA[3] = (double) a / 255.0;
	    break;
	case COLOR_STRING:
	    break;
	case COLOR_INDEX:
	    break;
	}
	return rc;
    }

    /* test for hsv value such as: ".6,.5,.3" */
    if (((c = *p) == '.') || isdigit(c)) {
	len = strlen((char*)p);
	if (len >= allocated) {
	    allocated = len + 1 + 10;
	    canon = grealloc(canon, allocated);
	    if (! canon) {
		rc = COLOR_MALLOC_FAIL;
		return rc;
	    }
	}
	q = canon;
	while ((c = *p++)) {
	    if (c == ',')
		c = ' ';
	    *q++ = c;
	}
	*q = '\0';

	if (sscanf((char *) canon, "%lf%lf%lf", &H, &S, &V) == 3) {
	    /* clip to reasonable values */
	    H = MAX(MIN(H, 1.0), 0.0);
	    S = MAX(MIN(S, 1.0), 0.0);
	    V = MAX(MIN(V, 1.0), 0.0);
	    switch (target_type) {
	    case HSVA_DOUBLE:
		color->u.HSVA[0] = H;
		color->u.HSVA[1] = S;
		color->u.HSVA[2] = V;
		color->u.HSVA[3] = 1.0; /* opaque */
		break;
	    case RGBA_BYTE:
		hsv2rgb(H, S, V, &R, &G, &B);
		color->u.rgba[0] = (int) (R * 255);
		color->u.rgba[1] = (int) (G * 255);
		color->u.rgba[2] = (int) (B * 255);
		color->u.rgba[3] = 255;	/* opaque */
		break;
	    case CMYK_BYTE:
		hsv2rgb(H, S, V, &R, &G, &B);
		rgb2cmyk(R, G, B, &C, &M, &Y, &K);
		color->u.cmyk[0] = (int) C *255;
		color->u.cmyk[1] = (int) M *255;
		color->u.cmyk[2] = (int) Y *255;
		color->u.cmyk[3] = (int) K *255;
		break;
	    case RGBA_WORD:
		hsv2rgb(H, S, V, &R, &G, &B);
		color->u.rrggbbaa[0] = (int) (R * 65535);
		color->u.rrggbbaa[1] = (int) (G * 65535);
		color->u.rrggbbaa[2] = (int) (B * 65535);
		color->u.rrggbbaa[3] = 65535;	/* opaque */
		break;
	    case RGBA_DOUBLE:
		hsv2rgb(H, S, V, &R, &G, &B);
		color->u.RGBA[0] = R;
		color->u.RGBA[1] = G;
		color->u.RGBA[2] = B;
		color->u.RGBA[3] = 1.0;	/* opaque */
		break;
	    case COLOR_STRING:
		break;
	    case COLOR_INDEX:
		break;
	    }
	    return rc;
	}
    }

    /* test for known color name (generic, not renderer specific known names) */
    fake.name = resolveColor(str);
    if (!fake.name)
	return COLOR_MALLOC_FAIL;
    if ((last == NULL)
	|| (last->name[0] != fake.name[0])
	|| (strcmp(last->name, fake.name))) {
	last = (hsvrgbacolor_t *) bsearch((void *) &fake,
				      (void *) color_lib,
				      sizeof(color_lib) /
				      sizeof(hsvrgbacolor_t), sizeof(fake),
				      colorcmpf);
    }
    if (last != NULL) {
	switch (target_type) {
	case HSVA_DOUBLE:
	    color->u.HSVA[0] = ((double) last->h) / 255.0;
	    color->u.HSVA[1] = ((double) last->s) / 255.0;
	    color->u.HSVA[2] = ((double) last->v) / 255.0;
	    color->u.HSVA[3] = ((double) last->a) / 255.0;
	    break;
	case RGBA_BYTE:
	    color->u.rgba[0] = last->r;
	    color->u.rgba[1] = last->g;
	    color->u.rgba[2] = last->b;
	    color->u.rgba[3] = last->a;
	    break;
	case CMYK_BYTE:
	    R = (last->r) / 255.0;
	    G = (last->g) / 255.0;
	    B = (last->b) / 255.0;
	    rgb2cmyk(R, G, B, &C, &M, &Y, &K);
	    color->u.cmyk[0] = (int) C * 255;
	    color->u.cmyk[1] = (int) M * 255;
	    color->u.cmyk[2] = (int) Y * 255;
	    color->u.cmyk[3] = (int) K * 255;
	    break;
	case RGBA_WORD:
	    color->u.rrggbbaa[0] = last->r * 65535 / 255;
	    color->u.rrggbbaa[1] = last->g * 65535 / 255;
	    color->u.rrggbbaa[2] = last->b * 65535 / 255;
	    color->u.rrggbbaa[3] = last->a * 65535 / 255;
	    break;
	case RGBA_DOUBLE:
	    color->u.RGBA[0] = last->r / 255.0;
	    color->u.RGBA[1] = last->g / 255.0;
	    color->u.RGBA[2] = last->b / 255.0;
	    color->u.RGBA[3] = last->a / 255.0;
	    break;
	case COLOR_STRING:
	    break;
	case COLOR_INDEX:
	    break;
	}
	return rc;
    }

    /* if we're still here then we failed to find a valid color spec */
    rc = COLOR_UNKNOWN;
    switch (target_type) {
    case HSVA_DOUBLE:
	color->u.HSVA[0] = color->u.HSVA[1] = color->u.HSVA[2] = 0.0;
	color->u.HSVA[3] = 1.0; /* opaque */
	break;
    case RGBA_BYTE:
	color->u.rgba[0] = color->u.rgba[1] = color->u.rgba[2] = 0;
	color->u.rgba[3] = 255;	/* opaque */
	break;
    case CMYK_BYTE:
	color->u.cmyk[0] =
	    color->u.cmyk[1] = color->u.cmyk[2] = color->u.cmyk[3] = 0;
	break;
    case RGBA_WORD:
	color->u.rrggbbaa[0] = color->u.rrggbbaa[1] = color->u.rrggbbaa[2] = 0;
	color->u.rrggbbaa[3] = 65535;	/* opaque */
	break;
    case RGBA_DOUBLE:
	color->u.RGBA[0] = color->u.RGBA[1] = color->u.RGBA[2] = 0.0;
	color->u.RGBA[3] = 1.0;	/* opaque */
	break;
    case COLOR_STRING:
	break;
    case COLOR_INDEX:
	break;
    }
    return rc;
}