void SlidersController::updateBlackValues(QColor color) {
  slidersView->ui->kSlider->setK(color);
  
  blackSpinManualEdit = false;
  slidersView->ui->spBlack->setValue(color.black());
  
  slidersView->ui->cSlider->changeBlack(color);
  slidersView->ui->mSlider->changeBlack(color);
  slidersView->ui->ySlider->changeBlack(color);
}
Example #2
0
void ContinuousColorRange::add(const QVariant &v)
{
    if ( contains(v))
        return;
    QColor clr = toColor(v, defaultColorModel());
    if ( !clr.isValid())
        return;
    if ( defaultColorModel() == ColorRangeBase::cmRGBA){
        _limit1.setRed(std::min(_limit1.red(), clr.red()));
        _limit1.setGreen(std::min(_limit1.green(), clr.green()));
        _limit1.setBlue(std::min(_limit1.blue(), clr.blue()));
        _limit1.setAlpha(std::min(_limit1.alpha(), clr.alpha()));
        _limit2.setRed(std::max(_limit2.red(), clr.red()));
        _limit2.setGreen(std::max(_limit2.green(), clr.green()));
        _limit2.setBlue(std::max(_limit2.blue(), clr.blue()));
        _limit2.setAlpha(std::max(_limit2.alpha(), clr.alpha()));
    }else if (defaultColorModel() == ColorRangeBase::cmHSLA) {
        _limit1.setHsl(std::min(_limit1.hue(), clr.hue()),
                       std::min(_limit1.saturation(), clr.saturation()),
                       std::min(_limit1.lightness(), clr.lightness()));
        _limit1.setAlpha(std::min(_limit1.alpha(), clr.alpha()));
        _limit2.setHsl(std::max(_limit2.hue(), clr.hue()),
                       std::max(_limit2.saturation(), clr.saturation()),
                       std::max(_limit2.lightness(), clr.lightness()));
        _limit2.setAlpha(std::max(_limit2.alpha(), clr.alpha()));
    }
    else if ( defaultColorModel() == ColorRangeBase::cmCYMKA){
        _limit1.setCmyk(std::min(_limit1.cyan(), clr.cyan()),
                        std::min(_limit1.magenta(), clr.magenta()),
                        std::min(_limit1.yellow(), clr.yellow()),
                        std::min(_limit1.black(), clr.black()));
        _limit1.setAlpha(std::min(_limit1.alpha(), clr.alpha()));
        _limit2.setCmyk(std::max(_limit2.cyan(), clr.cyan()),
                        std::max(_limit2.magenta(), clr.magenta()),
                        std::max(_limit2.yellow(), clr.yellow()),
                        std::max(_limit2.black(), clr.black()));
        _limit2.setAlpha(std::max(_limit2.alpha(), clr.alpha()));

    }

}
PNM* HoughRectangles::transform()
{
	PNM* img = CornerHarris(image).transform();

	for (int i = 0; i < img->width(); i++)
	{
		for (int j = 0; j < img->height(); j++)
		{
			QColor color = QColor::fromRgb(img->pixel(i, j));
			if (color.black() != 255)
			{
				img = remove(i, j, i, j, img);
			}
		}
	}

	std::vector<std::pair<int, int>> points;

	for (int i = 0; i < img->width(); i++)
	{
		for (int j = 0; j < img->height(); j++)
		{
			QColor color = QColor::fromRgb(img->pixel(i, j));
			if (color.black() != 255)
			{
				points.push_back(std::make_pair(i, j));
			}
		}
	}

	for (int i = 0; i < points.size(); i++)
	{
		std::vector<std::pair<int, int>> corners = check_quadrat(points.at(i), img);
		if (corners.size() == 4)
		{
			img = drawQuadrat(corners, img);
		}
	}

    return img;
}
Example #4
0
void Predspracovanie::PixMap2Mat(const QPixmap &img){                  //funkcia nutná na konverziu 8bit obrazu z povodnej QPixmap
                                                                 //ktoru vyuziva QT Creator, vystupom je Maticu obrazu na pracu v OpenCV
    QImage image = img.toImage();
    QColor rgb;
    this->mat= Mat(image.height(),image.width(),CV_8UC1);
    for(int i=0;i<this->mat.rows;i++){
        for(int j=0;j<this->mat.cols;j++){
            rgb=image.pixel(j,i);
            this->mat.at<uchar>(i,j)=abs(rgb.black()-255);
        }
    }
}
Example #5
0
void ColorRangeBase::storeColor(const QColor& clr, QDataStream &stream)
{
    switch (defaultColorModel()){
    case ColorRangeBase::cmRGBA:
        stream << clr.red() << clr.green() << clr.blue() << clr.alpha();
        break;
    case ColorRangeBase::cmHSLA:
        stream << clr.hue() << clr.saturation() << clr.lightness() << clr.alpha();
        break;
    case ColorRangeBase::cmCYMKA:
        stream << clr.yellow() << clr.magenta() << clr.cyan() << clr.black();
        break;
    case ColorRangeBase::cmGREYSCALE:
        stream << clr.red();
    default:
        break;
    }
}
Example #6
0
void MainWindow::genScale()
{
    QColor tempColor;
    int grayColor;

    for (int i = 0; i< Img->width(); i++)
    {
        for (int j = 0; j < Img->height(); j++)
        {
            tempColor = Img->pixel(i, j);
            grayColor = (255 - tempColor.black());
            grayScale[grayColor]++;
            grayCumulativeScale[grayColor]++;
            average += grayColor;
        }
    }

    average /= (float)(Img->width() * Img->height());
}
Example #7
0
void tst_QColor::setCmyk()
{
    QColor color;

    for (int A = 0; A <= USHRT_MAX; ++A) {
        {
            // 0-255
            int a = A >> 8;
            color.setCmyk(0, 0, 0, 0, a);
            QCOMPARE(color.alpha(), a);

            int c, m, y, k, a2;
            color.getCmyk(&c, &m, &y, &k, &a2);
            QCOMPARE(a2, a);
        }

        {
            // 0.0-1.0
            qreal a = A / qreal(USHRT_MAX);
            color.setCmykF(0.0, 0.0, 0.0, 0.0, a);
            QCOMPARE(color.alphaF(), a);

            qreal c, m, y, k, a2;
            color.getCmykF(&c, &m, &y, &k, &a2);
            QCOMPARE(a2, a);
        }
    }

    for (int C = 0; C <= USHRT_MAX; ++C) {
        {
            // 0-255
            int c = C >> 8;
            color.setCmyk(c, 0, 0, 0, 0);
            QCOMPARE(color.cyan(), c);

            int c2, m, y, k, a;
            color.getCmyk(&c2, &m, &y, &k, &a);
            QCOMPARE(c2, c);
        }

        {
            // 0.0-1.0
            qreal c = C / qreal(USHRT_MAX);
            color.setCmykF(c, 0.0, 0.0, 0.0, 0.0);
            QCOMPARE(color.cyanF(), c);

            qreal c2, m, y, k, a;
            color.getCmykF(&c2, &m, &y, &k, &a);
            QCOMPARE(c2, c);
        }
    }

    for (int M = 0; M <= USHRT_MAX; ++M) {
        {
            // 0-255
            int m = M >> 8;
            color.setCmyk(0, m, 0, 0, 0);
            QCOMPARE(color.magenta(), m);

            int c, m2, y, k, a;
            color.getCmyk(&c, &m2, &y, &k, &a);
            QCOMPARE(m2, m);
        }

        {
            // 0.0-1.0
            qreal m = M / qreal(USHRT_MAX);
            color.setCmykF(0.0, m, 0.0, 0.0, 0.0);
            QCOMPARE(color.magentaF(), m);

            qreal c, m2, y, k, a;
            color.getCmykF(&c, &m2, &y, &k, &a);
            QCOMPARE(m2, m);
        }
    }

    for (int Y = 0; Y <= USHRT_MAX; ++Y) {
        {
            // 0-255
            int y = Y >> 8;
            color.setCmyk(0, 0, y, 0, 0);
            QCOMPARE(color.yellow(), y);

            int c, m, y2, k, a;
            color.getCmyk(&c, &m, &y2, &k, &a);
            QCOMPARE(y2, y);
        }

        {
            // 0.0-1.0
            qreal y = Y / qreal(USHRT_MAX);
            color.setCmykF(0.0, 0.0, y, 0.0, 0.0);
            QCOMPARE(color.yellowF(), y);

            qreal c, m, y2, k, a;
            color.getCmykF(&c, &m, &y2, &k, &a);
            QCOMPARE(y2, y);
        }
    }

    for (int K = 0; K <= USHRT_MAX; ++K) {
        {
            // 0-255
            int k = K >> 8;
            color.setCmyk(0, 0, 0, k, 0);
            QCOMPARE(color.black(), k);

            int c, m, y, k2, a;
            color.getCmyk(&c, &m, &y, &k2, &a);
            QCOMPARE(k2, k);
        }

        {
            // 0.0-1.0
            qreal k = K / qreal(USHRT_MAX);
            color.setCmykF(0.0, 0.0, 0.0, k, 0.0);
            QCOMPARE(color.blackF(), k);

            qreal c, m, y, k2, a;
            color.getCmykF(&c, &m, &y, &k2, &a);
            QCOMPARE(k2, k);
        }
    }
}
Example #8
0
void processar::aplicar(QImage tempImg, int brilho, bool isImage){


    if(isImage)
    {
        QColor tempColor;
        QRgb   cor;
        //int r, g, b;
        int cinza;

        //if (tempImg.isGrayscale()){
            for(int i = 0; i < tempImg.width(); i++){
                for(int j = 0; j < tempImg.height(); j++){
                    tempColor = tempImg.pixel(i,j);

                    cinza = 255 - (brilho + tempColor.black());

                    if (cinza > 255)
                        cinza = 255;
                    else if(cinza < 0)
                        cinza = 0;

                    cor = qRgb(cinza, cinza, cinza);
                    tempImg.setPixel(i, j, cor);

                } //Final For Altura

            } //Final For Largura

            imgFinal -> setPixmap(QPixmap::fromImage(tempImg));
            imgFinal -> adjustSize();

            imgFinalCopy = tempImg.copy();
            processado = true;

        //} //Final do If greyScale

        /*for(int i = 0; i < tempImg.width(); i++){
            for(int j = 0; j < tempImg.height(); j++){

                tempColor = tempImg.pixel(i,j);

                r = brilho + tempColor.red();
                g = brilho + tempColor.green();
                b = brilho + tempColor.blue();

                if (r > 255)
                    r = 255;
                else if (r < 0)
                    r = 0;

                if (g > 255)
                    g = 255;
                else if (g < 0)
                    g = 0;

                if (b > 255)
                    b = 255;
                else if (b < 0)
                    b = 0;

                cor = qRgb(r, g, b);
                tempImg.setPixel(i, j, cor);
            }

            imgFinal -> setPixmap(QPixmap::fromImage(tempImg));
            imgFinal -> adjustSize();

            imgFinalCopy = tempImg.copy();
            processado = true;
        } */


    }
}
Example #9
0
ccImage* ccCalibratedImage::orthoRectifyAsImage(CCLib::GenericIndexedCloud* keypoints3D,
												std::vector<KeyPoint>& keypointsImage,
												double& pixelSize,
												double* minCorner/*=0*/,
												double* maxCorner/*=0*/,
												double* realCorners/*=0*/) const
{
	double a[3],b[3],c[3];

	if (!computeOrthoRectificationParams(keypoints3D,keypointsImage,a,b,c))
		return 0;

	const double& a0 = a[0];
	const double& a1 = a[1];
	const double& a2 = a[2];
	const double& b0 = b[0];
	const double& b1 = b[1];
	const double& b2 = b[2];
	//const double& c0 = c[0];
	const double& c1 = c[1];
	const double& c2 = c[2];

	//first, we compute the ortho-rectified image corners
	double corners[8];
	double xi,yi,qi;

	double halfWidth = (double)m_width/2.0;
	double halfHeight = (double)m_height/2.0;

	//top-left
	xi = -halfWidth;
	yi = -halfHeight;
	qi = 1.0+c1*xi+c2*yi;
	corners[0] = (a0+a1*xi+a2*yi)/qi;
	corners[1] = (b0+b1*xi+b2*yi)/qi;

	//top-right
	xi =  halfWidth;
	yi = -halfHeight;
	qi = 1.0+c1*xi+c2*yi;
	corners[2] = (a0+a1*xi+a2*yi)/qi;
	corners[3] = (b0+b1*xi+b2*yi)/qi;

	//bottom-right
	xi = halfWidth;
	yi = halfHeight;
	qi = 1.0+c1*xi+c2*yi;
	corners[4] = (a0+a1*xi+a2*yi)/qi;
	corners[5] = (b0+b1*xi+b2*yi)/qi;

	//bottom-left
	xi = -halfWidth;
	yi =  halfHeight;
	qi = 1.0+c1*xi+c2*yi;
	corners[6] = (a0+a1*xi+a2*yi)/qi;
	corners[7] = (b0+b1*xi+b2*yi)/qi;

	if (realCorners)
		memcpy(realCorners,corners,8*sizeof(double));

	//we look for min and max bounding box
	double minC[2] = {corners[0],corners[1]};
	double maxC[2] = {corners[0],corners[1]};

	for (unsigned k=1;k<4;++k)
	{
		const double* C = corners+2*k;
		if (minC[0] > C[0])
			minC[0] = C[0];
		else if (maxC[0] < C[0])
			maxC[0] = C[0];

		if (minC[1] > C[1])
			minC[1] = C[1];
		else if (maxC[1] < C[1])
			maxC[1] = C[1];
	}

	//output 3D boundaries (optional)
	if (minCorner)
	{
		minCorner[0]=minC[0];
		minCorner[1]=minC[1];
	}
	if (maxCorner)
	{
		maxCorner[0]=maxC[0];
		maxCorner[1]=maxC[1];
	}

	double dx = maxC[0]-minC[0];
	double dy = maxC[1]-minC[1];

	double _pixelSize = pixelSize;
	if (_pixelSize<=0.0)
	{
		unsigned maxSize = std::max(m_width,m_height);
		_pixelSize = std::max(dx,dy)/(double)maxSize;
	}
	unsigned w = (unsigned)((double)dx/_pixelSize);
	unsigned h = (unsigned)((double)dy/_pixelSize);

	QImage orthoImage(w,h,QImage::Format_ARGB32);
	if (orthoImage.isNull()) //not enough memory!
		return 0;

	QColor color;
	int blackValue = color.black();

	for (unsigned i=0;i<w;++i)
	{
		double xip = minC[0]+(double)i*_pixelSize;
		for (unsigned j=0;j<h;++j)
		{
			double yip = minC[1]+(double)j*_pixelSize;
			double q = (c2*xip-a2)*(c1*yip-b1)-(c2*yip-b2)*(c1*xip-a1);
			double p = (a0-xip)*(c1*yip-b1)-(b0-yip)*(c1*xip-a1);
			double yi = p/q;
			yi += halfHeight;
			int y = (int)yi;

			if (y>=0 && y<(int)m_height)
			{
				q = (c1*xip-a1)*(c2*yip-b2)-(c1*yip-b1)*(c2*xip-a2);
				p = (a0-xip)*(c2*yip-b2)-(b0-yip)*(c2*xip-a2);
				double  xi = p/q;
				xi += halfWidth;
				int x = (int)xi;

				if (x>=0 && x<(int)m_width)
				{
					QRgb rgb = m_image.pixel(x,y);
					//pure black pixels are treated as transparent ones!
					if (rgb != blackValue)
						orthoImage.setPixel(i,h-1-j,rgb);
					else
						orthoImage.setPixel(i,h-1-j,qRgba(qRed(rgb),qGreen(rgb),qBlue(rgb),0));
				}
				else
				{
					orthoImage.setPixel(i,h-1-j,qRgba(0,0,0,0)); //black by default
				}
			}
			else
			{
				orthoImage.setPixel(i,h-1-j,qRgba(0,0,0,0)); //black by default
			}
		}
	}

	//output pixel size (auto)
	pixelSize = _pixelSize;

	return new ccImage(orthoImage,getName());
}