Example #1
0
jas_cmprof_t *jas_cmprof_createfromiccprof(jas_iccprof_t *iccprof)
{
	jas_cmprof_t *prof;
	jas_icchdr_t icchdr;
	jas_cmpxformseq_t *fwdpxformseq;
	jas_cmpxformseq_t *revpxformseq;

	prof = 0;
	fwdpxformseq = 0;
	revpxformseq = 0;

	if (!(prof = jas_cmprof_create()))
		goto error;
	jas_iccprof_gethdr(iccprof, &icchdr);
	if (!(prof->iccprof = jas_iccprof_copy(iccprof)))
		goto error;
	prof->clrspc = icctoclrspc(icchdr.colorspc, 0);
	prof->refclrspc = icctoclrspc(icchdr.refcolorspc, 1);
	prof->numchans = jas_clrspc_numchans(prof->clrspc);
	prof->numrefchans = jas_clrspc_numchans(prof->refclrspc);

	if (prof->numchans == 1) {
		if (mono(prof->iccprof, 0, &fwdpxformseq))
			goto error;
		if (mono(prof->iccprof, 1, &revpxformseq))
			goto error;
	} else if (prof->numchans == 3) {
		if (triclr(prof->iccprof, 0, &fwdpxformseq))
			goto error;
		if (triclr(prof->iccprof, 1, &revpxformseq))
			goto error;
	}
	prof->pxformseqs[SEQFWD(0)] = fwdpxformseq;
	prof->pxformseqs[SEQREV(0)] = revpxformseq;

#if 0
	if (prof->numchans > 1) {
		lut(prof->iccprof, 0, PER, &pxformseq);
		pxformseqs_set(prof, SEQFWD(PER), pxformseq);
		lut(prof->iccprof, 1, PER, &pxformseq);
		pxformseqs_set(prof, SEQREV(PER), pxformseq);
		lut(prof->iccprof, 0, CLR, &pxformseq);
		pxformseqs_set(prof, SEQREV(CLR), pxformseq);
		lut(prof->iccprof, 1, CLR, &pxformseq);
		pxformseqs_set(prof, SEQREV(CLR), pxformseq);
		lut(prof->iccprof, 0, SAT, &pxformseq);
		pxformseqs_set(prof, SEQREV(SAT), pxformseq);
		lut(prof->iccprof, 1, SAT, &pxformseq);
		pxformseqs_set(prof, SEQREV(SAT), pxformseq);
	}
#endif

	return prof;

error:
	if (fwdpxformseq) {
		jas_cmpxformseq_destroy(fwdpxformseq);
	}
	if (revpxformseq) {
		jas_cmpxformseq_destroy(revpxformseq);
	}
	if (prof) {
		jas_cmprof_destroy(prof);
	}

	return 0;
}
void LevelAnalyzedImage::analyze()
{
    if ( inputImage_.empty() ) return;

    cv::Mat grayImage;
    {
        std::lock_guard<std::mutex> lock(inputImageMutex_);
        cv::cvtColor(inputImage_, grayImage, CV_BGR2GRAY);
    }

    // Noise reduction
    cv::medianBlur(grayImage, grayImage, 5);

    // Contrast collection
    cv::Mat lut(1, 256, CV_8U);
    for (int i = 0; i < 256; ++i) {
        lut.at<unsigned char>(i) = (i < threshold_) ? (std::pow(i, 2) / threshold_) : (256 - std::pow(i, 2) / std::pow(256, 2));
        // lut.at<unsigned char>(i) = 255 / (1 + std::exp(-contrast_ * (i - 128) / 255));
    }
    cv::LUT(grayImage, lut, grayImage);

    // Check each cell color
    std::vector<int> heights;
    for (auto rect : targetRects_) { // copy
        // To fill gaps
        rect.width  += 1;
        rect.height += 1;

        // Check ROI
        if ( !(rect.x >= 0 && rect.width  >= 0 && rect.x + rect.width  <= grayImage.cols &&
               rect.y >= 0 && rect.height >= 0 && rect.y + rect.height <= grayImage.rows) ) {
            qDebug() << "targetRects contains invalid rect data.";
            continue;
        }

        // Calculate average color
        cv::Mat roiImage = grayImage(rect);
        if (rect.width > 3 && rect.height > 3) {
            rect.x += rect.width  / 3;
            rect.y += rect.height / 3;
            rect.width  /= 3;
            rect.height /= 3;
        }
        cv::Mat averageRoiImage = grayImage(rect);
        cv::Mat rowAverage, average;
        cv::reduce(averageRoiImage, rowAverage, 0, CV_REDUCE_AVG);
        cv::reduce(rowAverage, average,  1, CV_REDUCE_AVG);

        // Set all pixels in ROI as its average color
        auto averageValue = average.at<unsigned char>(0);
        roiImage = cv::Scalar(averageValue);

        // Set results
        auto brickDetected = averageValue > threshold_ ? 1 : 0;
        heights.push_back(brickDetected);
    }

    // check change
    addHeightsCache(heights);
    checkResult();

    {
        std::lock_guard<std::mutex> lock(mutex_);
        cv::cvtColor(grayImage, image_, CV_GRAY2BGR);
        emit imageChanged();
    }

    emit update();
}
Example #3
0
/* virtual */ opera_update_checker::status::Status OAUCRequestImpl::ComposeMainUpdatePart(const UpdateDataProvider& provider, bool with_metrics)
{
  try
  {
    if (!document_.RootElement())
      document_.Parse(update_request_root);

    if (document_.Error())
      return opera_update_checker::status::StatusCode::FAILED;

    TiXmlDocument temp;
    TIXML_STRING os(provider.GetOsName() ? provider.GetOsName() : "");
    TIXML_STRING encoded_os;
    TIXML_STRING ver(provider.GetOsVersion() ? provider.GetOsVersion() : "");
    TIXML_STRING encoded_ver;
    TIXML_STRING arch(provider.GetArch() ? provider.GetArch() : "");
    TIXML_STRING encoded_arch;
    TIXML_STRING package(provider.GetPackage() ? provider.GetPackage() : "");
    TIXML_STRING encoded_package;
    const char* cuuid;
    opera_update_checker::status::Status status = provider.GetUUID(cuuid);
    if (status != opera_update_checker::status::StatusCode::OK)
      return status;
    TIXML_STRING uuid(cuuid ? cuuid : "");
    TIXML_STRING encoded_uuid;
    const char* clut;
    status = provider.GetLUT(clut);
    if (status != opera_update_checker::status::StatusCode::OK)
      return status;
    TIXML_STRING lut(clut ? clut : "");
    TIXML_STRING encoded_lut;
    TIXML_STRING firstrunversion(provider.GetFirstRunVersion() ? provider.GetFirstRunVersion() : "");
    TIXML_STRING encoded_firstrunversion;
    TIXML_STRING firstrunts(provider.GetFirstRunTimestamp() ? provider.GetFirstRunTimestamp() : "");
    TIXML_STRING encoded_firstrunts;
    TIXML_STRING user_loc(provider.GetUserLocation() ? provider.GetUserLocation() : "");
    TIXML_STRING encoded_user_loc;
    TIXML_STRING detected_loc(provider.GetDetectedLocation() ? provider.GetDetectedLocation() : "");
    TIXML_STRING encoded_detected_loc;
    TIXML_STRING active_loc(provider.GetActiveLocation() ? provider.GetActiveLocation() : "");
    TIXML_STRING encoded_active_loc;
    TIXML_STRING region(provider.GetRegion() ? provider.GetRegion() : "");
    TIXML_STRING encoded_region;

    document_.EncodeString(os, &encoded_os);
    document_.EncodeString(ver, &encoded_ver);
    document_.EncodeString(arch, &encoded_arch);
    document_.EncodeString(package, &encoded_package);
    document_.EncodeString(uuid, &encoded_uuid);
    document_.EncodeString(lut, &encoded_lut);
    document_.EncodeString(firstrunversion, &encoded_firstrunversion);
    document_.EncodeString(firstrunts, &encoded_firstrunts);
    document_.EncodeString(user_loc, &encoded_user_loc);
    document_.EncodeString(detected_loc, &encoded_detected_loc);
    document_.EncodeString(active_loc, &encoded_active_loc);
    document_.EncodeString(region, &encoded_region);
    sprintf(shared_work_buffer,
            update_metrics_part_template,
            encoded_os.c_str() ? encoded_os.c_str() : "",
            encoded_ver.c_str() ? encoded_ver.c_str() : "",
            encoded_arch.c_str() ? encoded_arch.c_str() : "",
            encoded_package.c_str() ? encoded_package.c_str() : "",
            encoded_uuid.c_str() ? encoded_uuid.c_str() : "",
            encoded_lut.c_str() ? encoded_lut.c_str() : "",
            encoded_firstrunversion.c_str() ? encoded_firstrunversion.c_str() : "",
            encoded_firstrunts.c_str() ? encoded_firstrunts.c_str() : "",
            encoded_user_loc.c_str() ? encoded_user_loc.c_str() : "",
            encoded_detected_loc.c_str() ? encoded_detected_loc.c_str() : "",
            encoded_active_loc.c_str() ? encoded_active_loc.c_str() : "",
            encoded_region.c_str() ? encoded_region.c_str() : "");

    temp.Parse(shared_work_buffer);
    if (temp.Error())
      return opera_update_checker::status::StatusCode::FAILED;

    OAUC_ASSERT(document_.RootElement() && document_.RootElement()->FirstChildElement());
    TiXmlElement* child = document_.RootElement()->FirstChildElement();
    while (opera_update_checker::system_utils::SystemUtils::strnicmp(child->Value(), "system", 6) != 0)
    {
      child = child->NextSiblingElement();
      OAUC_ASSERT(child);
    }

    TiXmlElement* elm = temp.RootElement();
    do
    {
      if (with_metrics || opera_update_checker::system_utils::SystemUtils::strnicmp(elm->Value(), "metrics", 7) != 0)
        child->InsertEndChild(*elm);

      elm = elm->NextSiblingElement();
    }
    while (elm);
  }
  catch (...)
  {
    return opera_update_checker::status::StatusCode::OOM;
  }
  return opera_update_checker::status::StatusCode::OK;
}
Example #4
0
myvector<int> create_srandom(const int tau, int& spread, libbase::int32u& seed,
      const int max_attempts)
   {
   // set up time-keepers
   libbase::pacifier p;
   // set up random-number generation
   libbase::truerand trng;
   libbase::randgen seeder;
   seeder.seed(trng.ival());
   libbase::randgen prng;
   // initialize space for results
   myvector<int> lut(tau);

   bool failed = true;
   while (failed)
      {
      std::cerr << "Searching for solution at spread " << spread << std::endl;
      // loop for a number of attempts at the given Spread, then
      // reduce and continue as necessary
      libbase::cputimer tmain("Attempt timer");
      int attempt;
      for (attempt = 0; attempt < max_attempts && failed; attempt++)
         {
         std::cerr << p.update(attempt, max_attempts);
         // re-seed random generator
         seed = seeder.ival();
         prng.seed(seed);
         // set up working variables
         mylist<int> unused(tau);
         unused.sequence();
         // loop to fill all entries in the interleaver - or until we fail
         failed = false;
         for (int i = 0; i < tau && !failed; i++)
            {
            // set up for the current entry
            mylist<pair<int> > untried = unused.pairup();
            // loop for the current entry
            // until we find a suitable value or totally fail trying
            while (!failed)
               {
               // choose a random number from what's left to try
               mylist<pair<int> >::iterator ndx = untried.getiteratorat(
                     prng.ival(untried.size()));
               const int n = ndx->value;
               // if it's no good remove it from the list of options
               if (!satisfiesspread(lut, n, i, spread))
                  {
                  untried.erase(ndx);
                  failed = untried.empty();
                  continue;
                  }
               // if it's a suitable value, insert & mark as used
               else
                  {
                  unused.erase(ndx->index);
                  lut(i) = n;
                  break;
                  }
               }
            }
         }
      // show user how fast we're working
      tmain.stop();
      std::cerr << "Attempts: " << attempt << " in " << tmain << std::endl;
      std::cerr << "Speed: " << double(attempt) / tmain.elapsed()
            << " attempts/sec" << std::endl;
      // if this failed, prepare for the next attempt
      if (failed)
         spread--;
      }

   // stop timers
   std::cerr << p.update(max_attempts, max_attempts);

   return lut;
   }
Example #5
0
 vector<tBGRA> getLinearLut() {
    vector<tBGRA> lut( 256 );
    boost::iota( lut, incrementBGRA() );
    return lut;
 }
Example #6
0
std::vector< uint8_t > deserializeLookupTable1D( const Event& event )
{
    auto data = GetLookupTable1D( event.getData( ));
    LBASSERT( data->lut()->Length() == 1024 );
    return deserializeVector( data->lut( ));
}
Example #7
0
float aux_func(float a, float b) {
	return Sign(a)*Sign(b)*std::min(abs(a), abs(b)) + lut(a, b);
}
int ImageProcCV::imageNormalize(cv::Mat &_input, cv::Mat &_output, int method)
{
    //this function only accepts CV_8U data type
    int retVal = NO_ERRORS;
    cv::Mat& input = _input;
    cv::Mat& output = _output;

    //check input
    if (!input.data)
    {
        retVal = EMPTY_IMAGE_MTRX;
        return retVal;
    }
    else if (input.type() != CV_8UC1)
    {
        retVal = INV_IMG_TYPE;
        return retVal;
    }

    output = cv::Mat::zeros(input.size(),CV_64F);

    int rows = input.rows;
    int cols = input.cols;
    if(input.isContinuous() && output.isContinuous())
    {
        cols *= rows;
        rows = 1;
    }
    switch (method)
    {
    case NORM_GLOBAL:

        for(int i = 0; i < rows; i++)
        {
            uchar *_input = input.ptr<uchar>(i);
            double *_output = output.ptr<double>(i);
            for(int j = 0; j < cols; j++)
            {

                //double val = (double)_input[j]/255.0f;
                _output[j] = (double)_input[j]/255.0f;
            }
        }

        break;

    case NORM_STD:
        int max = 0, min = 255;
        //finding maximu and minimum elements in the matrix

        max = *std::max_element(input.begin<uchar>(), input.end<uchar>());
        min = *std::min_element(input.begin<uchar>(), input.end<uchar>());
        /*for(cv::MatIterator_<uchar> it = input.begin<uchar>(); it != input.end<uchar>(); it++)
        {
            if(*it >= max)
            {
                max = *it;
            }
            if(*it <= min)
            {
                min = *it;
            }
        }*/
        if(min == max)
        {
            retVal = EQUAL_INTENSITY_PIXELS;
        }
        else
        {
            retVal = NO_ERRORS;
        }
        cv::Mat lut(1, 256, CV_8U);
        uchar* p = lut.data;
        for( int i = 0; i < 256; ++i)
            p[i] = (i - min) /(double)((min == max)? 1:(max -min));
        cv::LUT(input,lut,output);
        break;

    }
    return retVal;
}
Example #9
0
void log_to_linear_node_t::do_process( const image::const_image_view_t& src, const image::image_view_t& dst, const render::render_context_t& context)
{
    if( get_value<int>( param( "convert")))
    {
        switch( get_value<int>( param( "method")))
        {
        case cineon_conv:
        {
            IECore::LinearToCineonDataConversion<float,boost::uint16_t> conv( get_value<float>( param( "cin_gamma")),
                    get_value<float>( param( "cin_white")),
                    get_value<float>( param( "cin_black")));

            boost::scoped_array<boost::uint16_t> lut( new boost::uint16_t[1<<16]);
            init_lut( lut.get(), conv);

            //cineon_linear_to_log_fun f( conv);
            cineon_linear_to_log_lut_fun f( lut.get());
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case redlog_conv:
        {
            IECore::LinearToCineonDataConversion<float,boost::uint16_t> conv( 1.02f, 1023, 0);

            boost::scoped_array<boost::uint16_t> lut( new boost::uint16_t[1<<16]);
            init_lut( lut.get(), conv);

            //cineon_linear_to_log_fun f( conv);
            cineon_linear_to_log_lut_fun f( lut.get());
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case exrdpx_conv:
        {
            exrdpx_linear_to_log_fun f;
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;
        }
    }
    else
    {
        switch( get_value<int>( param( "method")))
        {
        case cineon_conv:
        {
            IECore::CineonToLinearDataConversion<boost::uint16_t, float> conv( get_value<float>( param( "cin_gamma")),
                    get_value<float>( param( "cin_white")),
                    get_value<float>( param( "cin_black")));
            cineon_log_to_linear_fun f( conv);
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case redlog_conv:
        {
            IECore::CineonToLinearDataConversion<boost::uint16_t, float> conv( 1.02f, 1023, 0);
            cineon_log_to_linear_fun f( conv);
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;

        case exrdpx_conv:
        {
            exrdpx_log_to_linear_fun f;
            boost::gil::tbb_transform_pixels( src, dst, f);
        }
        break;
        }
    }
}
Example #10
0
bool task3_5(const cv::Mat& image, const cv::Mat& orig) {
    cv::Mat grey, tmp, res;
    image.copyTo(grey);
    grey.convertTo(grey, CV_32F);

    grey.copyTo(res);
    res.convertTo(res, CV_8U);
    std::vector<cv::Mat> planes(2, cv::Mat());
    std::vector<cv::Mat> polar(2, cv::Mat());

    cv::dft(grey, tmp, cv::DFT_COMPLEX_OUTPUT);
    cv::split(tmp, planes);
    cv::cartToPolar(planes[0], planes[1], polar[0], polar[1]);

    int cx = polar[0].cols / 2;
    int cy = polar[0].rows / 2;
    cv::Point max;

    cv::Mat top = polar[0].rowRange(0, cx);
    cv::Mat bot = polar[0].rowRange(cx, polar[0].rows);

    int row = 0;
    do {
        cv::minMaxLoc(top.rowRange(row++, top.rows), 0, 0, 0, &max);
    } while (max.x == 0);


    int r = 3;

    cv::Mat noizeCol = polar[0].colRange(max.x - r, max.x + r);
    cv::Mat noizeRow = polar[0].rowRange(max.y - r, max.y + r);
    cv::Mat blurCol = polar[0].colRange(max.x - 12, max.x - 12 + 2 * r);
    cv::Mat blurRow = polar[0].rowRange(max.y - 3 * r, max.y - r);

    blurCol.copyTo(noizeCol);
    blurRow.copyTo(noizeRow);


    cv::Mat noizeColB = polar[0].colRange(polar[0].cols - max.x - r, polar[0].cols - max.x + r);
    cv::Mat noizeRowB = polar[0].rowRange(polar[0].rows - max.y - r, polar[0].rows - max.y + r);

    blurCol.copyTo(noizeColB);
    blurRow.copyTo(noizeRowB);

    cv::Mat roi = polar[0];
    cv::Mat mean, stddev, tmp1;
    roi = roi.colRange(max.x + 20, roi.cols - max.x - 20).rowRange(max.y + 20, roi.cols - max.y - 20);
    for (int i = 0; i < roi.rows; ++i) {
        cv::Mat row = roi.row(i);
        cv::meanStdDev(row, mean, stddev);
        float m = mean.at<double>(0, 0);
        float st = stddev.at<double>(0, 0);
        for (Mfit mfit = row.begin<float>(); mfit != row.end<float>(); ++mfit) {
            if (*mfit > m + 1.5 * st) {
                *mfit = 0.5 * m;
            }
        }
    }
    visualization(polar[0], tmp);

    //    
    //    
    //    cv::namedWindow("Lesson 2", CV_WINDOW_NORMAL);
    //    cv::imshow("Lesson 2", tmp);
    //    cv::waitKey(0);


    cv::polarToCart(polar[0], polar[1], planes[0], planes[1]);
    cv::merge(planes, tmp);
    cv::dft(tmp, tmp, cv::DFT_SCALE | cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT);



    tmp.convertTo(tmp, CV_8U);



    cv::Mat lut(1, 256, CV_32F, cv::Scalar(0));
    for (int i = 0; i < 256; ++i) {
        lut.at<float>(0, i) = i;
    }

    for (int i = 65; i < 200; ++i) {
        lut.at<float>(0, i) = i - 30;
    }
    
    for (int i = 200; i < 220; ++i) {
        lut.at<float>(0, i) = i - 20;
    }
    
    lut.convertTo(lut, CV_8U);

    tmp.convertTo(tmp, CV_8U);

    cv::normalize(tmp, tmp, 0, 255, cv::NORM_MINMAX);
    
    cv::LUT(tmp, lut, tmp);


    cv::GaussianBlur(tmp, tmp, cv::Size(3, 3), 1);
    cv::medianBlur(tmp, tmp, 3);
    cv::Mat result;
    cv::matchTemplate(orig, tmp, result, CV_TM_SQDIFF);
    std::cout << "RMSE Task 3.5: " << result / (orig.cols * orig.rows) << std::endl;

    concatImages(res, tmp, res);
    cv::absdiff(tmp, orig, tmp);
    concatImages(res, tmp, res);

    cv::absdiff(image, orig, tmp);
    concatImages(res, tmp, res);
    concatImages(res, orig, res);

//    cv::namedWindow("Lesson 2", CV_WINDOW_NORMAL);
//    cv::imshow("Lesson 2", res);
//    cv::waitKey(0);

    return cv::imwrite(PATH + "Task3_5.jpg", res);
}
Example #11
0
void threshold(const cv::Mat& src, uchar t, cv::Mat& dst) {
    cv::Mat lut(1, 256, CV_8U, cv::Scalar(0));
    lut.colRange(t + 1, lut.cols) = cv::Scalar(255);
    cv::LUT(src, lut, dst);
}