Exemple #1
0
float SAHer::Objective(const cv::Rect &roi) {
    float wg = .98, wt = 1 - wg;
    int blur_range = 11;
    cv::Point lu(std::max(0, roi.x - 2*blur_range), std::max(0, roi.y - 2*blur_range)), rd(std::min(w_, roi.x + roi.width + 2*blur_range), std::min(h_, roi.y + roi.height + 2*blur_range));
    cv::Point offset1(blur_range, blur_range);

    if ( roi.x - blur_range < 0) {
        offset1.x = 0;
    } else if (roi.x - blur_range*2 < 0) {
        offset1.x = roi.x - blur_range;
    }
    if ( roi.y - blur_range < 0) {
        offset1.y = 0;
    } else if (roi.y - blur_range*2 < 0) {
        offset1.y = roi.y - blur_range;
    }
    cv::Rect new_roi(lu, rd);
    cv::Mat src_roi = src_image_(new_roi), halftone_roi = halftone_image_(new_roi);

    cv::Rect sub_roi = cv::Rect(offset1.x, offset1.y, std::min(roi.width + 2*blur_range, new_roi.width - offset1.x), std::min(roi.height + 2*blur_range, new_roi.height - offset1.y));
    //info() << "begin" << roi.x << roi.y << roi.width << roi.height << offset1.x << offset1.y << new_roi.x << new_roi.y << new_roi.width << new_roi.height;
    cv::Mat ssim_map = ssim(src_roi, halftone_roi)(sub_roi);
    //info () << "end";
    float mean_ssim = float(cv::mean(ssim_map)[0]);

    cv::Mat gI, gH, se;
    cv::GaussianBlur(src_roi, gI, cv::Size(blur_range, blur_range), 0);
    cv::GaussianBlur(halftone_roi, gH, cv::Size(blur_range, blur_range), 0);
    cv::subtract(gI(sub_roi), gH(sub_roi), se);
    cv::multiply(se, se, se);

    float gaussian_diff = float(cv::mean(se)[0]);

    return wg*gaussian_diff + wt*(1.f - mean_ssim);
}
Exemple #2
0
 static date_type local_dst_start_day(year_type year)
 {
   if (year >= year_type(2007)) {
     //second sunday in march
     nkday ssim(nkday::second, Sunday, gregorian::Mar);
     return ssim.get_date(year);      
   } else {
     //first sunday in april
     fkday fsia(Sunday, gregorian::Apr);
     return fsia.get_date(year);      
   }
 }
Exemple #3
0
static double imgerr(char *m, float *x, float *y, int n)
{
	double r;
	if (false);
	else if (0 == strcmp(m, "MSE"))   r = mean_square_error(x, y, n);
	else if (0 == strcmp(m, "RMSE"))  r = root_mean_square_error(x, y, n);
	else if (0 == strcmp(m, "MAE"))   r = mean_absolute_error(x, y, n);
	else if (0 == strcmp(m, "UIQI"))  r = uiqi(x, y, n);
	else if (0 == strcmp(m, "SSIM"))  r = ssim(x, y, n);
	else if (0 == strcmp(m, "PSNR"))  r = psnr(x, y, n);
	else if (0 == strcmp(m, "NCC"))   r = ncc(x, y, n);
	else if (string_is_lp(m, &r))     r = ell_pee_distance(x, y, n, r);
	else fail("unrecognized metric \"%s\"", m);
	return r;
}
Exemple #4
0
int run_ssim(const char *fmt, const char *ref_path, const char *dis_path, int w, int h)
{
    int ret = 0;
    struct data *s;
    s = (struct data *)malloc(sizeof(struct data));
    s->format = fmt;
    s->width = w;
    s->height = h;

    ret = get_frame_offset(fmt, w, h, &(s->offset));
    if (ret)
    {
        goto fail_or_end;
    }

    if (!(s->ref_rfile = fopen(ref_path, "rb")))
    {
        fprintf(stderr, "fopen ref_path %s failed.\n", ref_path);
        ret = 1;
        goto fail_or_end;
    }
    if (!(s->dis_rfile = fopen(dis_path, "rb")))
    {
        fprintf(stderr, "fopen ref_path %s failed.\n", dis_path);
        ret = 1;
        goto fail_or_end;
    }

    ret = ssim(read_frame, s, w, h, fmt);

fail_or_end:
    if (s->ref_rfile)
    {
        fclose(s->ref_rfile);
    }
    if (s->dis_rfile)
    {
        fclose(s->dis_rfile);
    }
    if (s)
    {
        free(s);
    }
    return ret;
}