void GeneralizedPatchMatch::reconstErrorDisplay (const Mat& src, const Mat& dst, const dynamicArray2D<p_offset>& NearNei, int k, int time) {
    
    
    Mat temp = Mat::zeros(dst.size(), CV_64FC1), mapped = Mat::zeros(dst.size(), dst.type());
    
    
    for (int i = 0; i < mapped.rows; i ++) {
        for (int j = 0; j < mapped.cols; j ++) {
            
            mapped.at<Vec3d>(i, j) = src.at<Vec3d>(NearNei.get(i, j).get(k).offset + Point(j, i));
            
        }
    }
    
    for (int i = 0; i < dst.rows; i ++) {
        for (int j = 0; j < dst.cols; j ++) {
            
            temp.at<double>(i, j) = Vec3dDiff(dst.at<Vec3d>(i, j), mapped.at<Vec3d>(i, j));
            
        }
    }
    
//    double temp_max = maxMatItem(temp);
//    temp /= temp_max;
    
    temp = temp*3;
    
    showMat(temp, "error", time);
    
    temp.release();
}
// Display the reconstructed image according to the nearest neighbor field
void GeneralizedPatchMatch::reconstDisplay (const Mat& src, const dynamicArray2D<p_offset>& NearNei, int k, int time) {
    
    Mat mapped = Mat::zeros(NearNei.rows, NearNei.cols, CV_64FC3);
    
    for (int i = 0; i < mapped.rows; i ++) {
        for (int j = 0; j < mapped.cols; j ++) {
            
            mapped.at<Vec3d>(i, j) = src.at<Vec3d>(NearNei.get(i, j).get(k).offset + Point(j, i));
            
        }
    }
    
    showMat(mapped, "mapped", time);
    
    mapped.release();
}
void GeneralizedPatchMatch::RepetendDisplay(const cv::Mat src, const dynamicArray2D<p_offset> &NeaNei) {
    
    Mat temp = Mat::zeros(src.size(), CV_64FC1);
    
    for (int i = 0; i < temp.rows; i ++) {
        for (int j = 0; j < temp.cols; j ++) {
            
            for (int k = 0; k < NeaNei.get(i, j).size(); k ++) {
                
//                for (int p = -PATCHHEIGHT; p <= PATCHHEIGHT; p ++) {
//                    for (int q = -PATCHWIDTH; q <= PATCHWIDTH; q ++) {
                
                for (int n = 0; n < NeaNei.get(i, j).size(); n ++) {
                    temp.at<double>(i, j) += patchTool.SSD(src, NeaNei.get(i, j).get(k).offset + Point(j, i), src, NeaNei.get(i, j).get(n).offset + Point(j, i));
                }
                

                
//                    }
//                }
            }
            
            
        }
    }
    
    
//    double temp_max = maxMatItem(temp);
//    temp /= temp_max;
    
//    temp = Mat::ones(temp.size(), temp.type()) - temp;
    
    for (int i = 0; i < 10; i ++) {
        
        showMat(temp, "repetend", 0);
        
        temp = temp*(2);
    }
    
    
    temp.release();
    
}
void PatchMatch::distanceDisplay (RosMat<offsetElement> &array) {
    
    Mat temp = Mat::zeros(array.rows, array.cols, CV_64FC1);
    
    for (int i = 0; i < array.rows; i ++) {
        for (int j = 0; j < array.cols; j ++) {
            
            temp.at<double>(i, j) = sqrt(array.at(i, j).offset.x*array.at(i, j).offset.x + array.at(i, j).offset.y*array.at(i, j).offset.y);
            
        }
    }
    
    double temp_max = maxMatItem(temp);
    temp /= temp_max;
    
    showMat(temp, "distance", 0);

    temp.release();
    
}
void PatchMatch::reconstErrorDisplay (const Mat& dst, const Mat& mapped) {
    
    Mat temp = Mat::zeros(dst.size(), dst.type());
    
    Mat temp_dst = dst.clone();
    
    for (int i = 0; i < temp_dst.rows; i ++) {
        for (int j = 0; j < temp_dst.cols; j ++) {
            
            temp_dst.at<Vec3d>(i, j) = temp_dst.at<Vec3d>(i, j)*dst_mask.at<double>(i, j);
            
        }
    }
    
    
    absdiff(temp_dst, mapped, temp);
    
    
    showMat(temp, "error", 0);
    
    temp.release();
}
Esempio n. 6
0
	void showMat(const Mat &image)
	{
		if (image.type() == CV_32F) {
			double min, max;
			minMaxLoc(image, &min, &max);
			Mat image2 = image.clone();
			image2 -= min;
			image2 /= max;
			im = createIndexed(image.cols, image.rows);
			for (int i = 0; i < image2.cols; i++) {
				for (int j = 0; j < image2.rows; j++) {
					im.setPixel(i, j, image2.at<float>(j, i) * 255);
				}
			}
		} else if (image.type() == CV_32FC3) {
			vector<Mat> chs;
			cv::split(image, chs);
			showMat(chs[0]);
			return;
		} else
			im = QImage((const uchar *)image.data, image.cols,  image.rows, QImage::Format_RGB888);
		imgSource = image;
	}
void GeneralizedPatchMatch::distanceDisplay (const dynamicArray2D<p_offset>& array, int k, int time) {
    
    Mat temp = Mat::zeros(array.rows, array.cols, CV_64FC1);
    
    for (int i = 0; i < array.rows; i ++) {
        for (int j = 0; j < array.cols; j ++) {
            
            Point offset = array.get(i, j).get(k).offset;
            
            temp.at<double>(i, j) = sqrt(offset.x*offset.x + offset.y*offset.y);
            
        }
    }
    
    
    double temp_max = maxMatItem(temp);
    temp /= temp_max;
    
    showMat(temp, "distance", time);
    
    temp.release();
    
}
void PatchMatch::match(const cv::Mat &src, const cv::Mat &dst, RosMat<offsetElement> &NearNei) {
    
    double err = 0, pre_err = 0;
    do {
        
        pre_err = err;
        
        propagation(src, dst, NearNei);
        
        err = errorComputation(dst, coordinateMapping(src, NearNei));
//        cout<<err<<", "<<abs(err - pre_err)<<" : "<<HALTING_PARA*err<<endl;
        
        
    } while ( abs(err - pre_err) > HALTING_PARA*err);
    
    
    showMat(coordinateMapping(src, NearNei), "map", 0);
//    showMat(dst, "d", 1);
//    showMat(src, "s", 0);
    reconstErrorDisplay(dst, coordinateMapping(src, NearNei));
    distanceDisplay(NearNei);
    
    
}
Esempio n. 9
0
/*****************************************************************
 * 函数名称:showGame
 * 描述说明:显示连连看游戏
 * 输入参数:p_gameUi:游戏体指针
 * 输出参数:无
*****************************************************************/
void showGame(gameUi_t *p_gameUi)
{
	showWin(&p_gameUi->m_ui);
	showMat(&p_gameUi->m_mat);
	showTime(restTime);
}
Esempio n. 10
0
void PatchMatch::reconstDisplay (const Mat& src, RosMat<offsetElement>& NearNei) {
    
    showMat(coordinateMapping(src, NearNei), "Reconstructed dst", 0);
    
}