Beispiel #1
0
void GLView::process() {
    makeCurrent();
	if (m_image.isNull()) {
		m_dst = texture_2d();
		return;
	}

	int w = m_image.width();
	int h = m_image.height();

    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    glPushAttrib(GL_TEXTURE_BIT);

    texture_2d src(GL_RGB16F_ARB, m_image.width(), m_image.height(), GL_BGRA, GL_UNSIGNED_BYTE, m_image.bits());
    texture_2d lab = rgb2lab(src);
    texture_2d tfm = tangent_flow_map(src, sst_sigma);
    texture_2d bfe = (bf_ne > 0)? orientation_aligned_bilateral_filter(lab, tfm, bf_ne, bf_sigma_d, bf_sigma_r) : lab;
    texture_2d bfa = (bf_na > 0)? orientation_aligned_bilateral_filter(lab, tfm, bf_na, bf_sigma_d, bf_sigma_r) : lab;
    texture_2d edges = (fdog_type == 0)?
    fdog_filter(bfe, tfm, fdog_n, fdog_sigma_e, fdog_sigma_r, fdog_tau, fdog_sigma_m, fdog_phi) :
    dog_filter(bfe, fdog_n, fdog_sigma_e, fdog_sigma_r, fdog_tau, fdog_phi);
    texture_2d cq = color_quantization(bfa, cq_nbins, cq_phi_q, cq_filter);
    texture_2d cq_rgb = lab2rgb(cq);
    texture_2d ov = mix_filter(edges, cq_rgb, fdog_color);
    texture_2d result = fs_type? smooth_filter(tfm, ov, fs_type, fs_sigma) : ov;
    
    switch (preview) {
        case 0:
            m_dst = result;
            break;
		case 1:
			m_dst = src;
			break;
        case 2:
            m_dst = lic_filter(tfm, m_noise, 5.0);
            break;
        case 3:
            m_dst = lab2rgb(bfe);
            break;
        case 4:
            m_dst = lab2rgb(bfa);
            break;
        case 5:
            m_dst = edges;
            break;
        case 6:
            m_dst = cq_rgb;
            break;
    }

    glUseProgram(0);
    glPopAttrib();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
void work()
{
	// convert from rgb to lab
	for(int i = 0; i < n; ++i)
	{
		rgb2lab(getcol(img, i/h, i%h), ori[i]);
		res[i] = delta[i] = 0;
	}

	// calculate delta
	HANDLE thd[8];
	now = 0;
	for(int i = 0; i < 8; ++i)
		thd[i] = CreateThread(0, 0, calcDelta, 0, 0, 0);
	for(int i = 0; i < 8; ++i)
		WaitForSingleObject(thd[i], INFINITE);
	// calculate result
	for(int i = 1; i < n; ++i)
		res[i] = ( delta[i] - delta[i-1] + n * res[i-1]) / n;
	double sum = 0;
	for(int i = 0; i < n; i++) 
		sum += res[i] - ori[i][0];
	sum /= n;
	for(int i = 0; i < n; i++)
		res[i] = res[i] - sum;

	// output img
	for(int i = 0; i < n; ++i)
	{
		imgRes.at<uchar>(Point(i/h, i%h)) = lab2rgb(res[i]);
	}
}
Beispiel #3
0
// replace_luminance
void
replace_luminance(uint8& r1, uint8& g1, uint8& b1, uint8 r2, uint8 g2, uint8 b2)
{
	float CIEL1, CIEa1, CIEb1, CIEL2;//, CIEa2, CIEb2;
	rgb2lab(r1, g1, b1, CIEL1, CIEa1, CIEb1);
//	rgb2lab(r2, g2, b2, CIEL2, CIEa2, CIEb2);
	CIEL2 = ((linearTable[r2] + linearTable[g2] + linearTable[b2]) / 3.0) * 100.0;
	lab2rgb(CIEL2, CIEa1, CIEb1, r1, g1, b1);
}
Beispiel #4
0
// BANG - calculate and output
void cs_bang(t_cs *x)
{
	if(x->attr_mode == ps_rgb2hsl) rgb2hsl(x, x->val1, x->val2, x->val3); // first for speed
	else if(x->attr_mode == ps_hsl2rgb) hsl2rgb(x, x->val1, x->val2, x->val3);
	
	else if(x->attr_mode == ps_no_transform) no_transform(x);
	else if(x->attr_mode == ps_rgb2cmy) rgb2cmy(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_cmy2rgb) cmy2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2hsv) rgb2hsv(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_hsv2rgb) hsv2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2xyz) rgb2xyz(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_xyz2rgb) xyz2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2uvw) rgb2uvw(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_uvw2rgb) uvw2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2retinalcone) rgb2cone(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_retinalcone2rgb) cone2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2lab) rgb2lab(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_lab2rgb) lab2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2yiq) rgb2yiq(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_yiq2rgb) yiq2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2hls) rgb2hls(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_hls2rgb) hls2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2rgbcie) rgb2rgbcie(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgbcie2rgb) rgbcie2rgb(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgb2rgbsmpte) rgb2rgbsmpte(x, x->val1, x->val2, x->val3);
	else if(x->attr_mode == ps_rgbsmpte2rgb) rgbsmpte2rgb(x, x->val1, x->val2, x->val3);

	if(x->attr_outputtype == ps_packed){
		Atom temp_list[3];
		atom_setlong(temp_list+0, x->calc1);
		atom_setlong(temp_list+1, x->calc2);
		atom_setlong(temp_list+2, x->calc3);
		outlet_list(x->out1, 0L, 3, temp_list);	// output the result
	}	
	else{
		outlet_int(x->out3, x->calc3);	// output the result	
		outlet_int(x->out2, x->calc2);	// output the result	
		outlet_int(x->out1, x->calc1);	// output the result
	}	
}
Beispiel #5
0
Image ColorConvert::apply(Image im, string from, string to) {
    // check for the trivial case
    assert(from != to, "color conversion from %s to %s is pointless\n", from.c_str(), to.c_str());

    // unsupported destination color spaces
    if (to == "yuyv" ||
        to == "uyvy") {
        panic("Unsupported destination color space: %s\n", to.c_str());
    }

    // direct conversions that don't have to go via rgb
    if (from == "yuyv" && to == "yuv") {
        return yuyv2yuv(im);
    } else if (from == "uyvy" && to == "yuv") {
        return uyvy2yuv(im);
    } else if (from == "xyz" && to == "lab") {
        return xyz2lab(im);
    } else if (from == "lab" && to == "xyz") {
        return lab2xyz(im);
    } else if (from == "argb" && to == "xyz") {
        return argb2xyz(im);
    } else if (from == "xyz" && to == "argb") {
        return xyz2argb(im);
    } else if (from != "rgb" && to != "rgb") {
        // conversions that go through rgb
        Image halfway = apply(im, from, "rgb");
        return apply(halfway, "rgb", to);
    } else if (from == "rgb") { // from rgb
        if (to == "hsv" || to == "hsl" || to == "hsb") {
            return rgb2hsv(im);
        } else if (to == "yuv") {
            return rgb2yuv(im);
        } else if (to == "xyz") {
            return rgb2xyz(im);
        } else if (to == "y" || to == "gray" ||
                   to == "grayscale" || to == "luminance") {
            return rgb2y(im);
        } else if (to == "lab") {
            return rgb2lab(im);
        } else if (to == "argb") {
            return rgb2argb(im);
        } else {
            panic("Unknown color space %s\n", to.c_str());
        }
    } else { //(to == "rgb")
        if (from == "hsv" || from == "hsl" || from == "hsb") {
            return hsv2rgb(im);
        } else if (from == "yuv") {
            return yuv2rgb(im);
        } else if (from == "xyz") {
            return xyz2rgb(im);
        } else if (from == "y" || from == "gray" ||
                   from == "grayscale" || from == "luminance") {
            return y2rgb(im);
        } else if (from == "lab") {
            return lab2rgb(im);
        } else if (from == "uyvy") {
            return uyvy2rgb(im);
        } else if (from == "yuyv") {
            return yuyv2rgb(im);
        } else if (from == "argb") {
            return argb2rgb(im);
        } else {
            panic("Unknown color space %s\n", from.c_str());
        }
    }

    // keep the compiler happy
    return Image();

}