图像修复-CDD修复模型

原理:

 

 

 C++代码(灰度图像):

//CDD Inpaint
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <time.h>

using namespace cv;
using namespace std;

enum { PIXEL_WHITE = 1 };
typedef struct coord
{
	int i;
	int j;
	int color;
}Coord;

std::vector<Coord> create_mask(cv::Mat& mask);

void CDD_GRAY(
	cv::Mat& input_array, std::vector<Coord>& mask_array, cv::Mat& output_array,
	int* total_iters, int total_stages, float* lambdas, float* as);

int main(int argc, char* argv[])
{
	cv::Mat output_array;

	/* Create the windows */
	cv::namedWindow("1", cv::WINDOW_AUTOSIZE);
	cv::namedWindow("2", cv::WINDOW_AUTOSIZE);
	cv::namedWindow("3", cv::WINDOW_AUTOSIZE);

	/* Load and normalize the image */
	cv::Mat image_array = cv::imread("CDD.png");
	image_array.convertTo(image_array, CV_32FC1);
	cv::cvtColor(image_array, image_array, cv::COLOR_BGR2GRAY);
	cv::normalize(image_array, image_array, 0, 1, cv::NORM_MINMAX, CV_32FC1);
	cv::imshow("1", image_array);

	/* Load the mask and fill the vector*/
	cv::Mat mask_array = cv::imread("1.png");
	std::vector<Coord> mask_data = create_mask(mask_array);

	/*
		CDD PDE Inpainting.
	*/
	int total_iters[] = { 6000 };
	int total_stages = 2;
	float lambdas[] = { 0.2 };
	float as[] = { 0.5 };
	CDD_GRAY(image_array, mask_data, output_array, total_iters, total_stages, lambdas, as);

	cv::normalize(output_array, output_array, 0, 255.0, cv::NORM_MINMAX, CV_8UC1);
	output_array.convertTo(output_array, CV_8UC1);
	/* Display the output */

	cv::imshow("2", mask_array);
	cv::imshow("3", output_array);
	cv::waitKey(0);
}

void CDD_GRAY(
	cv::Mat& input_array, std::vector<Coord>& mask_array, cv::Mat& output_array,
	int* total_iters, int total_stages, float* lambdas, float* as)
{
	typedef unsigned char logical_type;

	//初始化输出图像
	input_array.copyTo(output_array);
	//掩模图像的大小
	int size_mask = mask_array.size();
	//在每个stage计算CDD
	for (int stage = 0; stage < total_stages; stage++)
	{
		int total_iter = total_iters[stage];
		float lambda = lambdas[stage];
		float a = as[stage];

		float UO, UN, UW, US, UE, UNE, UNW, USW, USE;
		float Un, Ue, Uw, Us;
		float Wn, We, Ww, Ws;
		float Hon, Hoe, How, Hos;
		float Hoo;
		float Kn, Ke, Kw, Ks;
		float grad_E1, grad_O1, grad_W1, grad_S2, grad_N2, grad_O2;
		float grad_NE2, grad_NW1, grad_SW2, grad_SE2, grad_NE1, grad_NW2, grad_SE1, grad_SW1;
		float UNW1, UNW2,UNW3, UN2, UNE1, UNE2, UNE3,UE2, UW2, US2, USE1, USE2,USE3, USW1, USW2,USW3;

		//算法运行
		for (int iter = 0; iter < total_iter; iter++)
		{
			for (int cont = 0; cont < size_mask; cont++)
			{
				Coord coord = mask_array.at(cont);
				int row = coord.i;
				int col = coord.j;

				UO = input_array.at<float>(row, col);
				UW = input_array.at<float>(row - 1, col);
				UE = input_array.at<float>(row + 1, col);
				UN = input_array.at<float>(row, col + 1);
				US = input_array.at<float>(row, col - 1);

				UNW = input_array.at<float>(row - 1, col + 1);
				USW = input_array.at<float>(row - 1, col - 1);
				UNE = input_array.at<float>(row + 1, col + 1);
				USE = input_array.at<float>(row + 1, col - 1);

				UE2 = input_array.at<float>(row + 2, col);
				UW2 = input_array.at<float>(row - 2, col);
				US2 = input_array.at<float>(row, col - 2);
				UN2 = input_array.at<float>(row, col + 2);

				UNW1 = input_array.at<float>(row - 2, col + 1);
				UNW2 = input_array.at<float>(row - 1, col + 2);
				UNW3 = input_array.at<float>(row - 2, col + 2);

				UNE1 = input_array.at<float>(row + 1, col + 2);
				UNE2 = input_array.at<float>(row + 2, col + 1);
				UNE3 = input_array.at<float>(row + 2, col + 2);

				USE1 = input_array.at<float>(row + 2, col - 1);
				USE2 = input_array.at<float>(row + 1, col - 2);
				USE3 = input_array.at<float>(row + 2, col - 2);

				USW1 = input_array.at<float>(row - 1, col - 2);
				USW2 = input_array.at<float>(row - 2, col - 1);
				USW3 = input_array.at<float>(row - 2, col - 2);

				grad_O1 = ((UE - UO) / sqrt((UE - UO) * (UE - UO) + ((UNE - USE) / 2.0) * ((UNE - USE) / 2.0) + a * a)) - ((UW - UO) / sqrt((UW - UO) * (UW - UO) + ((UNW - USW) / 2.0) * ((UNW - USW) / 2.0) + a * a));
				grad_E1 = ((UE2 - UE) / sqrt((UE2 - UE) * (UE2 - UE) + ((UNE2 - USE1) / 2.0) * ((UNE2 - USE1) / 2.0) + a * a)) - ((UO - UE) / sqrt((UO - UE) * (UO - UE) + ((UN - US) / 2.0) * ((UN - US) / 2.0) + a * a));
				grad_W1 = ((UO - UW) / sqrt((UO - UW) * (UO - UW) + ((UN - US) / 2.0) * ((UN - US) / 2.0) + a * a)) - ((UW2 - UW) / sqrt((UW2 - UW) * (UW2 - UW) + ((UNW1 - USW2) / 2.0) * ((UNW1 - USW2) / 2.0) + a * a));
				grad_NW1 = ((UN - UNW) / sqrt((UN - UNW) * (UN - UNW) + ((UN2 - UO) / 2.0) * ((UN2 - UO) / 2.0) + a * a)) - ((UNW1 - UNW) / sqrt((UNW1 - UNW) * (UNW1 - UNW) + ((UNW3 - UW2) / 2.0) * ((UNW3 - UW2) / 2.0) + a * a));
				grad_SW1 = ((US - USW) / sqrt((US - USW) * (US - USW) + ((UO - US2) / 2.0) * ((UO - US2) / 2.0) + a * a)) - ((USW2 - USW) / sqrt((USW2 - USW) * (USW2 - USW) + ((UW2 - USW3) / 2.0) * ((UW2 - USW3) / 2.0) + a * a));
				grad_NE1 = ((UNE2 - UNE) / sqrt((UNE2 - UNE) * (UNE2 - UNE) + ((UNE3 - UE2) / 2.0) * ((UNE3 - UE2) / 2.0) + a * a)) - ((UN - UNE) / sqrt((UN - UNE) * (UN - UNE) + ((UN2 - UO) / 2.0) * ((UN2 - UO) / 2.0) + a * a));
				grad_SE1 = ((USE1 - USE) / sqrt((USE1 - USE) * (USE1 - USE) + ((UE2 - USE3) / 2.0) * ((UE2 - USE3) / 2.0) + a * a)) - ((US - USE) / sqrt((US - USE) * (US - USE) + ((UO - US2) / 2.0) * ((UO - US2) / 2.0) + a * a));
				grad_O2 = ((UN - UO) / sqrt((UN - UO) * (UN - UO) + ((UNE - UNW) / 2.0) * ((UNE - UNW) / 2.0) + a * a)) - ((US - UO) / sqrt((US - UO) * (US - UO) + ((USE - USW) / 2.0) * ((USE - USW) / 2.0) + a * a));
				grad_S2 = ((UO - US) / sqrt((UO - US) * (UO - US) + ((UE - UW) / 2.0) * ((UE - UW) / 2.0) + a * a)) - ((US2 - US) / sqrt((US2 - US) * (US2 - US) + ((USE2 - USW1) / 2.0) * ((USE2 - USW1) / 2.0) + a * a));
				grad_N2 = ((UN2 - UN) / sqrt((UN2 - UN) * (UN2 - UN) + ((UNE1 - UNW2) / 2.0) * ((UNE1 - UNW2) / 2.0) + a * a)) - ((UO - UN) / sqrt((UO - UN) * (UO - UN) + ((UE - UW) / 2.0) * ((UE - UW) / 2.0) + a * a));
				grad_NW2 = ((UNW2 - UNW) / sqrt((UNW2 - UNW) * (UNW2 - UNW) + ((UN2 - UNW3) / 2.0) * ((UN2 - UNW3) / 2.0) + a * a)) - ((UW - UNW) / sqrt((UW - UNW) * (UW - UNW) + ((UO - UW2) / 2.0) * ((UO - UW2) / 2.0) + a * a));
				grad_SW2 = ((UW - USW) / sqrt((UW - USW) * (UW - USW) + ((UO - UW2) / 2.0) * ((UO - UW2) / 2.0) + a * a)) - ((USW1 - USW) / sqrt((USW1 - USW) * (USW1 - USW) + ((US2 - USW3) / 2.0) * ((US2 - USW3) / 2.0) + a * a));
				grad_NE2 = ((UNE1 - UNE) / sqrt((UNE1 - UNE) * (UNE1 - UNE) + ((UNE3 - UN2) / 2.0) * ((UNE3 - UN2) / 2.0) + a * a)) - ((UE - UNE) / sqrt((UE - UNE) * (UE - UNE) + ((UE2 - UO) / 2.0) * ((UE2 - UO) / 2.0) + a * a));
				grad_SE2 = ((UE - USE) / sqrt((UE - USE) * (UE - USE) + ((UE2 - UO) / 2.0) * ((UE2 - UO) / 2.0) + a * a)) - ((USE2 - USE) / sqrt((USE2 - USE) * (USE2 - USE) + ((USE3 - US2) / 2.0) * ((USE3 - US2) / 2.0) + a * a));

				Kn = sqrt((grad_N2 - grad_O2) * (grad_N2 - grad_O2) + ((grad_NE1 - grad_NW1) / 2.0) * ((grad_NE1 - grad_NW1) / 2.0));
				Ke = sqrt((grad_E1 - grad_O1) * (grad_E1 - grad_O1) + ((grad_NE2 - grad_SE2) / 2.0) * ((grad_NE2 - grad_SE2) / 2.0));
				Kw = sqrt((grad_W1 - grad_O1) * (grad_W1 - grad_O1) + ((grad_NW2 - grad_SW2) / 2.0) * ((grad_NW2 - grad_SW2) / 2.0));
				Ks = sqrt((grad_S2 - grad_O2) * (grad_S2 - grad_O2) + ((grad_SE1 - grad_SW1) / 2.0) * ((grad_SE1 - grad_SW1) / 2.0));

				Un = sqrt((UO - UN) * (UO - UN) + ((UNE - UNW) / 2.0) * ((UNE - UNW) / 2.0));
				Ue = sqrt((UO - UE) * (UO - UE) + ((UNE - USE) / 2.0) * ((UNE - USE) / 2.0));
				Uw = sqrt((UO - UW) * (UO - UW) + ((UNW - USW) / 2.0) * ((UNW - USW) / 2.0));
				Us = sqrt((UO - US) * (UO - US) + ((USE - USW) / 2.0) * ((USE - USW) / 2.0));

				Wn = Kn / sqrt(Un * Un + a * a);
				We = Ke / sqrt(Ue * Ue + a * a);
				Ww = Kw / sqrt(Uw * Uw + a * a);
				Ws = Ks / sqrt(Us * Us + a * a);

				Hon = Wn / (Wn + We + Ww + Ws + lambda);
				Hoe = We / (Wn + We + Ww + Ws + lambda);
				How = Ww / (Wn + We + Ww + Ws + lambda);
				Hos = Ws / (Wn + We + Ww + Ws + lambda);

				Hoo = lambda / (Wn + We + Ww + Ws + lambda);

				input_array.at<float>(row, col) = (Hon * UN + Hoe * UE + How * UW + Hos * US + Hoo * UO);
				output_array.at<float>(row, col) = input_array.at<float>(row, col);
			}
			printf("%d\n", iter);
		}
	}
}

/*
	Save the inpainting domain to dinamic vector
*/
std::vector<Coord> create_mask(cv::Mat& mask)
{
	std::vector<Coord> mask_data;
	for (int i = 2; i < mask.rows - 2; i++)
	{
		for (int j = 2; j < mask.cols - 2; j++)
		{
			if (mask.at<cv::Vec3b>(i, j)[0] != 0)
			{
				Coord xy;
				xy.i = i;
				xy.j = j;
				xy.color = PIXEL_WHITE;
				mask_data.push_back(xy);
			}
		}
	}
	return mask_data;
}

C++代码(RGB图像):

//CDD Inpaint
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <time.h>

using namespace cv;
using namespace std;

enum { PIXEL_WHITE = 1 };
typedef struct coord 
{
	int i;
	int j;
	int color;
}Coord;

std::vector<Coord> create_mask(cv::Mat& mask);

void CDD_RGB(
	cv::Mat& input_array, std::vector<Coord>& mask_array, cv::Mat& output_array,
	int* total_iters, int total_stages, float* lambdas, float* as);

int main(int argc, char* argv[])
{
	cv::Mat output_array;

	/* Create the windows */
	cv::namedWindow("1", cv::WINDOW_AUTOSIZE);
	cv::namedWindow("2", cv::WINDOW_AUTOSIZE);
	cv::namedWindow("3", cv::WINDOW_AUTOSIZE);

	/* Load and normalize the image */
	cv::Mat image_array = cv::imread("CDD3.png");
	cv::imshow("1", image_array);
	image_array.convertTo(image_array, CV_32FC3);
	cv::normalize(image_array, image_array, 0, 1, cv::NORM_MINMAX, CV_32FC3);

	/* Load the mask and fill the vector*/
	cv::Mat mask_array = cv::imread("1.png");
	std::vector<Coord> mask_data = create_mask(mask_array);

	/*
		CDD PDE Inpainting.
	*/
	int total_iters[] = { 6000 };
	int total_stages = 2;
	float lambdas[] = { 0.2 };
	float as[] = { 0.5 };
        double t = getTickCount();//当前滴答数
	CDD_RGB(image_array, mask_data, output_array, total_iters, total_stages, lambdas, as);
        t = ((double)getTickCount() - t) / getTickFrequency();
	printf("算法用时:%f秒\n", t);
	cv::normalize(output_array, output_array, 0, 255.0, cv::NORM_MINMAX, CV_8UC3);
	output_array.convertTo(output_array, CV_8UC3);

	imwrite("resjsj.png", output_array);
	/* Display the output */
	cv::imshow("2", mask_array);
	cv::imshow("3", output_array);
	cv::waitKey(0);
}

void CDD_RGB(
	cv::Mat& input_array, std::vector<Coord>& mask_array, cv::Mat& output_array,
	int* total_iters, int total_stages, float* lambdas, float* as)
{
	typedef unsigned char logical_type;

	//初始化输出图像
	input_array.copyTo(output_array);
	//掩模图像的大小
	int size_mask = mask_array.size();
	//在每个stage计算CDD
	for (int stage = 0; stage < total_stages; stage++)
	{
		int total_iter = total_iters[stage];
		float lambda = lambdas[stage];
		float a = as[stage];
		float UO1,UO2,UO3,UN1,UN2,UN3,UW1,UW2,UW3,US1,US2,US3,UE1,UE2,UE3,UNE1,UNE2,UNE3,UNW1,UNW2,UNW3,USW1,USW2,USW3,USE1,USE2,USE3;
		float Un1, Ue1, Uw1, Us1, Un2, Ue2, Uw2, Us2, Un3, Ue3, Uw3, Us3;
		float Wn1, We1, Ww1, Ws1, Wn2, We2, Ww2, Ws2, Wn3, We3, Ww3, Ws3;
		float Hon1, Hoe1, How1, Hos1, Hon2, Hoe2, How2, Hos2, Hon3, Hoe3, How3, Hos3;
		float Hoo1,Hoo2,Hoo3;
		float Kn1, Ke1, Kw1, Ks1, Kn2, Ke2, Kw2, Ks2, Kn3, Ke3, Kw3, Ks3;
		float grad_E11, grad_O11, grad_W11, grad_S21, grad_N21, grad_O21;
		float grad_NE21, grad_NW11, grad_SW21, grad_SE21, grad_NE11, grad_NW21, grad_SE11, grad_SW11;
		float UNW11, UNW21, UN21, UNE11, UNE21, UE21, UW21, US21, USE11, USE21, USW11, USW21;
		float grad_E12, grad_O12, grad_W12, grad_S22, grad_N22, grad_O22;
		float grad_NE22, grad_NW12, grad_SW22, grad_SE22, grad_NE12, grad_NW22, grad_SE12, grad_SW12;
		float UNW12, UNW22, UN22, UNE12, UNE22, UE22, UW22, US22, USE12, USE22, USW12, USW22;
		float grad_E13, grad_O13, grad_W13, grad_S23, grad_N23, grad_O23;
		float grad_NE23, grad_NW13, grad_SW23, grad_SE23, grad_NE13, grad_NW23, grad_SE13, grad_SW13;
		float UNW13, UNW23, UN23, UNE13, UNE23, UE23, UW23, US23, USE13, USE23, USW13, USW23;
		float UNW31, UNW32, UNW33, UNE31, UNE32, UNE33, USW31, USW32, USW33, USE31, USE32, USE33;

		//算法运行
		for (int iter = 0; iter < total_iter; iter++)
		{
			for (int cont = 0; cont < size_mask; cont++)
			{
				Coord coord = mask_array.at(cont);
				int row = coord.i;
				int col = coord.j;

				UO1 = input_array.at<cv::Vec3f>(row, col)[0];
				UO2 = input_array.at<cv::Vec3f>(row, col)[1];
				UO3 = input_array.at<cv::Vec3f>(row, col)[2];

				UW1 = input_array.at<cv::Vec3f>(row - 1, col)[0];
				UW2 = input_array.at<cv::Vec3f>(row - 1, col)[1];
				UW3 = input_array.at<cv::Vec3f>(row - 1, col)[2];

				UE1 = input_array.at<cv::Vec3f>(row + 1, col)[0];
				UE2 = input_array.at<cv::Vec3f>(row + 1, col)[1];
				UE3 = input_array.at<cv::Vec3f>(row + 1, col)[2];

				UN1 = input_array.at<cv::Vec3f>(row, col + 1)[0];
				UN2 = input_array.at<cv::Vec3f>(row, col + 1)[1];
				UN3 = input_array.at<cv::Vec3f>(row, col + 1)[2];

				US1 = input_array.at<cv::Vec3f>(row, col - 1)[0];
				US2 = input_array.at<cv::Vec3f>(row, col - 1)[1];
				US3 = input_array.at<cv::Vec3f>(row, col - 1)[2];

				UNW1 = input_array.at<cv::Vec3f>(row - 1, col + 1)[0];
				UNW2 = input_array.at<cv::Vec3f>(row - 1, col + 1)[1];
				UNW3 = input_array.at<cv::Vec3f>(row - 1, col + 1)[2];

				USW1 = input_array.at<cv::Vec3f>(row - 1, col - 1)[0];
				USW2 = input_array.at<cv::Vec3f>(row - 1, col - 1)[1];
				USW3 = input_array.at<cv::Vec3f>(row - 1, col - 1)[2];

				UNE1 = input_array.at<cv::Vec3f>(row + 1, col + 1)[0];
				UNE2 = input_array.at<cv::Vec3f>(row + 1, col + 1)[1];
				UNE3 = input_array.at<cv::Vec3f>(row + 1, col + 1)[2];

				USE1 = input_array.at<cv::Vec3f>(row + 1, col - 1)[0];
				USE2 = input_array.at<cv::Vec3f>(row + 1, col - 1)[1];
				USE3 = input_array.at<cv::Vec3f>(row + 1, col - 1)[2];

				UNW11 = input_array.at<cv::Vec3f>(row - 2, col + 1)[0];
				UNW12 = input_array.at<cv::Vec3f>(row - 2, col + 1)[1];
				UNW13 = input_array.at<cv::Vec3f>(row - 2, col + 1)[2];
				UNW21 = input_array.at<cv::Vec3f>(row - 1, col + 2)[0];
				UNW22 = input_array.at<cv::Vec3f>(row - 1, col + 2)[1];
				UNW23 = input_array.at<cv::Vec3f>(row - 1, col + 2)[2];
				UNW31 = input_array.at<cv::Vec3f>(row - 2, col + 2)[0];
				UNW32 = input_array.at<cv::Vec3f>(row - 2, col + 2)[1];
				UNW33 = input_array.at<cv::Vec3f>(row - 2, col + 2)[2];

				UN21 = input_array.at<cv::Vec3f>(row, col + 2)[0];
				UN22 = input_array.at<cv::Vec3f>(row, col + 2)[1];
				UN23 = input_array.at<cv::Vec3f>(row, col + 2)[2];

				UNE11 = input_array.at<cv::Vec3f>(row + 1, col + 2)[0];
				UNE12 = input_array.at<cv::Vec3f>(row + 1, col + 2)[1];
				UNE13 = input_array.at<cv::Vec3f>(row + 1, col + 2)[2];
				UNE21 = input_array.at<cv::Vec3f>(row + 2, col + 1)[0];
				UNE22 = input_array.at<cv::Vec3f>(row + 2, col + 1)[1];
				UNE23 = input_array.at<cv::Vec3f>(row + 2, col + 1)[2];
				UNE31 = input_array.at<cv::Vec3f>(row + 2, col + 2)[0];
				UNE32 = input_array.at<cv::Vec3f>(row + 2, col + 2)[1];
				UNE33 = input_array.at<cv::Vec3f>(row + 2, col + 2)[2];

				UE21 = input_array.at<cv::Vec3f>(row + 2, col)[0];
				UE22 = input_array.at<cv::Vec3f>(row + 2, col)[1];
				UE23 = input_array.at<cv::Vec3f>(row + 2, col)[2];

				UW21 = input_array.at<cv::Vec3f>(row - 2, col)[0];
				UW22 = input_array.at<cv::Vec3f>(row - 2, col)[1];
				UW23 = input_array.at<cv::Vec3f>(row - 2, col)[2];

				US21 = input_array.at<cv::Vec3f>(row, col - 2)[0];
				US22 = input_array.at<cv::Vec3f>(row, col - 2)[1];
				US23 = input_array.at<cv::Vec3f>(row, col - 2)[2];

				USE11 = input_array.at<cv::Vec3f>(row + 2, col - 1)[0];
				USE12 = input_array.at<cv::Vec3f>(row + 2, col - 1)[1];
				USE13 = input_array.at<cv::Vec3f>(row + 2, col - 1)[2];
				USE21 = input_array.at<cv::Vec3f>(row + 1, col - 2)[0];
				USE22 = input_array.at<cv::Vec3f>(row + 1, col - 2)[1];
				USE23 = input_array.at<cv::Vec3f>(row + 1, col - 2)[2];
				USE31 = input_array.at<cv::Vec3f>(row + 2, col - 2)[0];
				USE32 = input_array.at<cv::Vec3f>(row + 2, col - 2)[1];
				USE33 = input_array.at<cv::Vec3f>(row + 2, col - 2)[2];

				USW11 = input_array.at<cv::Vec3f>(row - 1, col - 2)[0];
				USW12 = input_array.at<cv::Vec3f>(row - 1, col - 2)[1];
				USW13 = input_array.at<cv::Vec3f>(row - 1, col - 2)[2];
				USW21 = input_array.at<cv::Vec3f>(row - 2, col - 1)[0];
				USW22 = input_array.at<cv::Vec3f>(row - 2, col - 1)[1];
				USW23 = input_array.at<cv::Vec3f>(row - 2, col - 1)[2];
				USW31 = input_array.at<cv::Vec3f>(row - 2, col - 2)[0];
				USW32 = input_array.at<cv::Vec3f>(row - 2, col - 2)[1];
				USW33 = input_array.at<cv::Vec3f>(row - 2, col - 2)[2];

				grad_O11 = ((UE1 - UO1) / sqrt((UE1 - UO1) * (UE1 - UO1) + ((UNE1 - USE1) / 2.0) * ((UNE1 - USE1) / 2.0) + a * a)) - ((UW1 - UO1) / sqrt((UW1 - UO1) * (UW1 - UO1) + ((UNW1 - USW1) / 2.0) * ((UNW1 - USW1) / 2.0) + a * a));
				grad_E11 = ((UE21 - UE1) / sqrt((UE21 - UE1) * (UE21 - UE1) + ((UNE21 - USE11) / 2.0) * ((UNE21 - USE11) / 2.0) + a * a)) - ((UO1 - UE1) / sqrt((UO1 - UE1) * (UO1 - UE1) + ((UN1 - US1) / 2.0) * ((UN1 - US1) / 2.0) + a * a));
				grad_W11 = ((UO1 - UW1) / sqrt((UO1 - UW1) * (UO1 - UW1) + ((UN1 - US1) / 2.0) * ((UN1 - US1) / 2.0) + a * a)) - ((UW21 - UW1) / sqrt((UW21 - UW1) * (UW21 - UW1) + ((UNW11 - USW21) / 2.0) * ((UNW11 - USW21) / 2.0) + a * a));
				grad_NW11 = ((UN1 - UNW1) / sqrt((UN1 - UNW1) * (UN1 - UNW1) + ((UN21 - UO1) / 2.0) * ((UN21 - UO1) / 2.0) + a * a)) - ((UNW11 - UNW1) / sqrt((UNW11 - UNW1) * (UNW11 - UNW1) + ((UNW31 - UW21) / 2.0) * ((UNW31 - UW21) / 2.0) + a * a));
				grad_SW11 = ((US1 - USW1) / sqrt((US1 - USW1) * (US1 - USW1) + ((UO1 - US21) / 2.0) * ((UO1 - US21) / 2.0) + a * a)) - ((USW21 - USW1) / sqrt((USW21 - USW1) * (USW21 - USW1) + ((UW21 - USW31) / 2.0) * ((UW21 - USW31) / 2.0) + a * a));
				grad_NE11 = ((UNE21 - UNE1) / sqrt((UNE21 - UNE1) * (UNE21 - UNE1) + ((UNE31 - UE21) / 2.0) * ((UNE31 - UE21) / 2.0) + a * a)) - ((UN1 - UNE1) / sqrt((UN1 - UNE1) * (UN1 - UNE1) + ((UN21 - UO1) / 2.0) * ((UN21 - UO1) / 2.0) + a * a));
				grad_SE11 = ((USE11 - USE1) / sqrt((USE11 - USE1) * (USE11 - USE1) + ((UE21 - USE31) / 2.0) * ((UE21 - USE31) / 2.0) + a * a)) - ((US1 - USE1) / sqrt((US1 - USE1) * (US1 - USE1) + ((UO1 - US21) / 2.0) * ((UO1 - US21) / 2.0) + a * a));
				grad_O21 = ((UN1 - UO1) / sqrt((UN1 - UO1) * (UN1 - UO1) + ((UNE1 - UNW1) / 2.0) * ((UNE1 - UNW1) / 2.0) + a * a)) - ((US1 - UO1) / sqrt((US1 - UO1) * (US1 - UO1) + ((USE1 - USW1) / 2.0) * ((USE1 - USW1) / 2.0) + a * a));
				grad_S21 = ((UO1 - US1) / sqrt((UO1 - US1) * (UO1 - US1) + ((UE1 - UW1) / 2.0) * ((UE1 - UW1) / 2.0) + a * a)) - ((US21 - US1) / sqrt((US21 - US1) * (US21 - US1) + ((USE21 - USW11) / 2.0) * ((USE21 - USW11) / 2.0) + a * a));
				grad_N21 = ((UN21 - UN1) / sqrt((UN21 - UN1) * (UN21 - UN1) + ((UNE11 - UNW21) / 2.0) * ((UNE11 - UNW21) / 2.0) + a * a)) - ((UO1 - UN1) / sqrt((UO1 - UN1) * (UO1 - UN1) + ((UE1 - UW1) / 2.0) * ((UE1 - UW1) / 2.0) + a * a));
				grad_NW21 = ((UNW21 - UNW1) / sqrt((UNW21 - UNW1) * (UNW21 - UNW1) + ((UN21 - UNW31) / 2.0) * ((UN21 - UNW31) / 2.0) + a * a)) - ((UW1 - UNW1) / sqrt((UW1 - UNW1) * (UW1 - UNW1) + ((UO1 - UW21) / 2.0) * ((UO1 - UW21) / 2.0) + a * a));
				grad_SW21 = ((UW1 - USW1) / sqrt((UW1 - USW1) * (UW1 - USW1) + ((UO1 - UW21) / 2.0) * ((UO1 - UW21) / 2.0) + a * a)) - ((USW11 - USW1) / sqrt((USW11 - USW1) * (USW11 - USW1) + ((US21 - USW31) / 2.0) * ((US21 - USW31) / 2.0) + a * a));
				grad_NE21 = ((UNE11 - UNE1) / sqrt((UNE11 - UNE1) * (UNE11 - UNE1) + ((UNE31 - UN21) / 2.0) * ((UNE31 - UN21) / 2.0) + a * a)) - ((UE1 - UNE1) / sqrt((UE1 - UNE1) * (UE1 - UNE1) + ((UE21 - UO1) / 2.0) * ((UE21 - UO1) / 2.0) + a * a));
				grad_SE21 = ((UE1 - USE1) / sqrt((UE1 - USE1) * (UE1 - USE1) + ((UE21 - UO1) / 2.0) * ((UE21 - UO1) / 2.0) + a * a)) - ((USE21 - USE1) / sqrt((USE21 - USE1) * (USE21 - USE1) + ((USE31 - US21) / 2.0) * ((USE31 - US21) / 2.0) + a * a));

				Kn1 = sqrt((grad_N21 - grad_O21) * (grad_N21 - grad_O21) + ((grad_NE11 - grad_NW11) / 2.0) * ((grad_NE11 - grad_NW11) / 2.0));
				Ke1 = sqrt((grad_E11 - grad_O11) * (grad_E11 - grad_O11) + ((grad_NE21 - grad_SE21) / 2.0) * ((grad_NE21 - grad_SE21) / 2.0));
				Kw1 = sqrt((grad_W11 - grad_O11) * (grad_W11 - grad_O11) + ((grad_NW21 - grad_SW21) / 2.0) * ((grad_NW21 - grad_SW21) / 2.0));
				Ks1 = sqrt((grad_S21 - grad_O21) * (grad_S21 - grad_O21) + ((grad_SE11 - grad_SW11) / 2.0) * ((grad_SE11 - grad_SW11) / 2.0));

				grad_O12 = ((UE2 - UO2) / sqrt((UE2 - UO2) * (UE2 - UO2) + ((UNE2 - USE2) / 2.0) * ((UNE2 - USE2) / 2.0) + a * a)) - ((UW2 - UO2) / sqrt((UW2 - UO2) * (UW2 - UO2) + ((UNW2 - USW2) / 2.0) * ((UNW2 - USW2) / 2.0) + a * a));
				grad_E12 = ((UE22 - UE2) / sqrt((UE22 - UE2) * (UE22 - UE2) + ((UNE22 - USE12) / 2.0) * ((UNE22 - USE12) / 2.0) + a * a)) - ((UO2 - UE2) / sqrt((UO2 - UE2) * (UO2 - UE2) + ((UN2 - US2) / 2.0) * ((UN2 - US2) / 2.0) + a * a));
				grad_W12 = ((UO2 - UW2) / sqrt((UO2 - UW2) * (UO2 - UW2) + ((UN2 - US2) / 2.0) * ((UN2 - US2) / 2.0) + a * a)) - ((UW22 - UW2) / sqrt((UW22 - UW2) * (UW22 - UW2) + ((UNW12 - USW22) / 2.0) * ((UNW12 - USW22) / 2.0) + a * a));
				grad_NW12 = ((UN2 - UNW2) / sqrt((UN2 - UNW2) * (UN2 - UNW2) + ((UN22 - UO2) / 2.0) * ((UN22 - UO2) / 2.0) + a * a)) - ((UNW12 - UNW2) / sqrt((UNW12 - UNW2) * (UNW12 - UNW2) + ((UNW32 - UW22) / 2.0) * ((UNW32 - UW22) / 2.0) + a * a));
				grad_SW12 = ((US2 - USW2) / sqrt((US2 - USW2) * (US2 - USW2) + ((UO2 - US22) / 2.0) * ((UO2 - US22) / 2.0) + a * a)) - ((USW22 - USW2) / sqrt((USW22 - USW2) * (USW22 - USW2) + ((UW22 - USW32) / 2.0) * ((UW22 - USW32) / 2.0) + a * a));
				grad_NE12 = ((UNE22 - UNE2) / sqrt((UNE22 - UNE2) * (UNE22 - UNE2) + ((UNE32 - UE22) / 2.0) * ((UNE32 - UE22) / 2.0) + a * a)) - ((UN2 - UNE2) / sqrt((UN2 - UNE2) * (UN2 - UNE2) + ((UN22 - UO2) / 2.0) * ((UN22 - UO2) / 2.0) + a * a));
				grad_SE12 = ((USE12 - USE2) / sqrt((USE12 - USE2) * (USE12 - USE2) + ((UE22 - USE32) / 2.0) * ((UE22 - USE32) / 2.0) + a * a)) - ((US2 - USE2) / sqrt((US2 - USE2) * (US2 - USE2) + ((UO2 - US22) / 2.0) * ((UO2 - US22) / 2.0) + a * a));
				grad_O22 = ((UN2 - UO2) / sqrt((UN2 - UO2) * (UN2 - UO2) + ((UNE2 - UNW2) / 2.0) * ((UNE2 - UNW2) / 2.0) + a * a)) - ((US2 - UO2) / sqrt((US2 - UO2) * (US2 - UO2) + ((USE2 - USW2) / 2.0) * ((USE2 - USW2) / 2.0) + a * a));
				grad_S22 = ((UO2 - US2) / sqrt((UO2 - US2) * (UO2 - US2) + ((UE2 - UW2) / 2.0) * ((UE2 - UW2) / 2.0) + a * a)) - ((US22 - US2) / sqrt((US22 - US2) * (US22 - US2) + ((USE22 - USW12) / 2.0) * ((USE22 - USW12) / 2.0) + a * a));
				grad_N22 = ((UN22 - UN2) / sqrt((UN22 - UN2) * (UN22 - UN2) + ((UNE12 - UNW22) / 2.0) * ((UNE12 - UNW22) / 2.0) + a * a)) - ((UO2 - UN2) / sqrt((UO2 - UN2) * (UO2 - UN2) + ((UE2 - UW2) / 2.0) * ((UE2 - UW2) / 2.0) + a * a));
				grad_NW22 = ((UNW22 - UNW2) / sqrt((UNW22 - UNW2) * (UNW22 - UNW2) + ((UN22 - UNW32) / 2.0) * ((UN22 - UNW32) / 2.0) + a * a)) - ((UW2 - UNW2) / sqrt((UW2 - UNW2) * (UW2 - UNW2) + ((UO2 - UW22) / 2.0) * ((UO2 - UW22) / 2.0) + a * a));
				grad_SW22 = ((UW2 - USW2) / sqrt((UW2 - USW2) * (UW2 - USW2) + ((UO2 - UW22) / 2.0) * ((UO2 - UW22) / 2.0) + a * a)) - ((USW12 - USW2) / sqrt((USW12 - USW2) * (USW12 - USW2) + ((US22 - USW32) / 2.0) * ((US22 - USW32) / 2.0) + a * a));
				grad_NE22 = ((UNE12 - UNE2) / sqrt((UNE12 - UNE2) * (UNE12 - UNE2) + ((UNE32 - UN22) / 2.0) * ((UNE32 - UN22) / 2.0) + a * a)) - ((UE2 - UNE2) / sqrt((UE2 - UNE2) * (UE2 - UNE2) + ((UE22 - UO2) / 2.0) * ((UE22 - UO2) / 2.0) + a * a));
				grad_SE22 = ((UE2 - USE2) / sqrt((UE2 - USE2) * (UE2 - USE2) + ((UE22 - UO2) / 2.0) * ((UE22 - UO2) / 2.0) + a * a)) - ((USE22 - USE2) / sqrt((USE22 - USE2) * (USE22 - USE2) + ((USE32 - US22) / 2.0) * ((USE32 - US22) / 2.0) + a * a));

				Kn2 = sqrt((grad_N22 - grad_O22) * (grad_N22 - grad_O22) + ((grad_NE12 - grad_NW12) / 2.0) * ((grad_NE12 - grad_NW12) / 2.0));
				Ke2 = sqrt((grad_E12 - grad_O12) * (grad_E12 - grad_O12) + ((grad_NE22 - grad_SE22) / 2.0) * ((grad_NE22 - grad_SE22) / 2.0));
				Kw2 = sqrt((grad_W12 - grad_O12) * (grad_W12 - grad_O12) + ((grad_NW22 - grad_SW22) / 2.0) * ((grad_NW22 - grad_SW22) / 2.0));
				Ks2 = sqrt((grad_S22 - grad_O22) * (grad_S22 - grad_O22) + ((grad_SE12 - grad_SW12) / 2.0) * ((grad_SE12 - grad_SW12) / 2.0));

				grad_O13 = ((UE3 - UO3) / sqrt((UE3 - UO3) * (UE3 - UO3) + ((UNE3 - USE3) / 2.0) * ((UNE3 - USE3) / 2.0) + a * a)) - ((UW3 - UO3) / sqrt((UW3 - UO3) * (UW3 - UO3) + ((UNW3 - USW3) / 2.0) * ((UNW3 - USW3) / 2.0) + a * a));
				grad_E13 = ((UE23 - UE3) / sqrt((UE23 - UE3) * (UE23 - UE3) + ((UNE23 - USE13) / 2.0) * ((UNE23 - USE13) / 2.0) + a * a)) - ((UO3 - UE3) / sqrt((UO3 - UE3) * (UO3 - UE3) + ((UN3 - US3) / 2.0) * ((UN3 - US3) / 2.0) + a * a));
				grad_W13 = ((UO3 - UW3) / sqrt((UO3 - UW3) * (UO3 - UW3) + ((UN3 - US3) / 2.0) * ((UN3 - US3) / 2.0) + a * a)) - ((UW23 - UW3) / sqrt((UW23 - UW3) * (UW23 - UW3) + ((UNW13 - USW23) / 2.0) * ((UNW13 - USW23) / 2.0) + a * a));
				grad_NW13 = ((UN3 - UNW3) / sqrt((UN3 - UNW3) * (UN3 - UNW3) + ((UN23 - UO3) / 2.0) * ((UN23 - UO3) / 2.0) + a * a)) - ((UNW13 - UNW3) / sqrt((UNW13 - UNW3) * (UNW13 - UNW3) + ((UNW33 - UW23) / 2.0) * ((UNW33 - UW23) / 2.0) + a * a));
				grad_SW13 = ((US3 - USW3) / sqrt((US3 - USW3) * (US3 - USW3) + ((UO3 - US23) / 2.0) * ((UO3 - US23) / 2.0) + a * a)) - ((USW23 - USW3) / sqrt((USW23 - USW3) * (USW23 - USW3) + ((UW23 - USW33) / 2.0) * ((UW23 - USW33) / 2.0) + a * a));
				grad_NE13 = ((UNE23 - UNE3) / sqrt((UNE23 - UNE3) * (UNE23 - UNE3) + ((UNE33 - UE23) / 2.0) * ((UNE33 - UE23) / 2.0) + a * a)) - ((UN3 - UNE3) / sqrt((UN3 - UNE3) * (UN3 - UNE3) + ((UN23 - UO3) / 2.0) * ((UN23 - UO3) / 2.0) + a * a));
				grad_SE13 = ((USE13 - USE3) / sqrt((USE13 - USE3) * (USE13 - USE3) + ((UE23 - USE33) / 2.0) * ((UE23 - USE33) / 2.0) + a * a)) - ((US3 - USE3) / sqrt((US3 - USE3) * (US3 - USE3) + ((UO3 - US23) / 2.0) * ((UO3 - US23) / 2.0) + a * a));
				grad_O23 = ((UN3 - UO3) / sqrt((UN3 - UO3) * (UN3 - UO3) + ((UNE3 - UNW3) / 2.0) * ((UNE3 - UNW3) / 2.0) + a * a)) - ((US3 - UO3) / sqrt((US3 - UO3) * (US3 - UO3) + ((USE3 - USW3) / 2.0) * ((USE3 - USW3) / 2.0) + a * a));
				grad_S23 = ((UO3 - US3) / sqrt((UO3 - US3) * (UO3 - US3) + ((UE3 - UW3) / 2.0) * ((UE3 - UW3) / 2.0) + a * a)) - ((US23 - US3) / sqrt((US23 - US3) * (US23 - US3) + ((USE23 - USW13) / 2.0) * ((USE23 - USW13) / 2.0) + a * a));
				grad_N23 = ((UN23 - UN3) / sqrt((UN23 - UN3) * (UN23 - UN3) + ((UNE13 - UNW23) / 2.0) * ((UNE13 - UNW23) / 2.0) + a * a)) - ((UO3 - UN3) / sqrt((UO3 - UN3) * (UO3 - UN3) + ((UE3 - UW3) / 2.0) * ((UE3 - UW3) / 2.0) + a * a));
				grad_NW23 = ((UNW23 - UNW3) / sqrt((UNW23 - UNW3) * (UNW23 - UNW3) + ((UN23 - UNW33) / 2.0) * ((UN23 - UNW33) / 2.0) + a * a)) - ((UW3 - UNW3) / sqrt((UW3 - UNW3) * (UW3 - UNW3) + ((UO3 - UW23) / 2.0) * ((UO3 - UW23) / 2.0) + a * a));
				grad_SW23 = ((UW3 - USW3) / sqrt((UW3 - USW3) * (UW3 - USW3) + ((UO3 - UW23) / 2.0) * ((UO3 - UW23) / 2.0) + a * a)) - ((USW13 - USW3) / sqrt((USW13 - USW3) * (USW13 - USW3) + ((US23 - USW33) / 2.0) * ((US23 - USW33) / 2.0) + a * a));
				grad_NE23 = ((UNE13 - UNE3) / sqrt((UNE13 - UNE3) * (UNE13 - UNE3) + ((UNE33 - UN23) / 2.0) * ((UNE33 - UN23) / 2.0) + a * a)) - ((UE3 - UNE3) / sqrt((UE3 - UNE3) * (UE3 - UNE3) + ((UE23 - UO3) / 2.0) * ((UE23 - UO3) / 2.0) + a * a));
				grad_SE23 = ((UE3 - USE3) / sqrt((UE3 - USE3) * (UE3 - USE3) + ((UE23 - UO3) / 2.0) * ((UE23 - UO3) / 2.0) + a * a)) - ((USE23 - USE3) / sqrt((USE23 - USE3) * (USE23 - USE3) + ((USE33 - US23) / 2.0) * ((USE33 - US23) / 2.0) + a * a));

				Kn3 = sqrt((grad_N23 - grad_O23) * (grad_N23 - grad_O23) + ((grad_NE13 - grad_NW13) / 2.0) * ((grad_NE13 - grad_NW13) / 2.0));
				Ke3 = sqrt((grad_E13 - grad_O13) * (grad_E13 - grad_O13) + ((grad_NE23 - grad_SE23) / 2.0) * ((grad_NE23 - grad_SE23) / 2.0));
				Kw3 = sqrt((grad_W13 - grad_O13) * (grad_W13 - grad_O13) + ((grad_NW23 - grad_SW23) / 2.0) * ((grad_NW23 - grad_SW23) / 2.0));
				Ks3 = sqrt((grad_S23 - grad_O23) * (grad_S23 - grad_O23) + ((grad_SE13 - grad_SW13) / 2.0) * ((grad_SE13 - grad_SW13) / 2.0));			

				Un1 = sqrt((UO1 - UN1) * (UO1 - UN1) + ((UNE1 - UNW1) / 2.0) * ((UNE1 - UNW1) / 2.0));
				Ue1 = sqrt((UO1 - UE1) * (UO1 - UE1) + ((UNE1 - USE1) / 2.0) * ((UNE1 - USE1) / 2.0));
				Uw1 = sqrt((UO1 - UW1) * (UO1 - UW1) + ((UNW1 - USW1) / 2.0) * ((UNW1 - USW1) / 2.0));
				Us1 = sqrt((UO1 - US1) * (UO1 - US1) + ((USE1 - USW1) / 2.0) * ((USE1 - USW1) / 2.0));

				Un2 = sqrt((UO2 - UN2) * (UO2 - UN2) + ((UNE2 - UNW2) / 2.0) * ((UNE2 - UNW2) / 2.0));
				Ue2 = sqrt((UO2 - UE2) * (UO2 - UE2) + ((UNE2 - USE2) / 2.0) * ((UNE2 - USE2) / 2.0));
				Uw2 = sqrt((UO2 - UW2) * (UO2 - UW2) + ((UNW2 - USW2) / 2.0) * ((UNW2 - USW2) / 2.0));
				Us2 = sqrt((UO2 - US2) * (UO2 - US2) + ((USE2 - USW2) / 2.0) * ((USE2 - USW2) / 2.0));

				Un3 = sqrt((UO3 - UN3) * (UO3 - UN3) + ((UNE3 - UNW3) / 2.0) * ((UNE3 - UNW3) / 2.0));
				Ue3 = sqrt((UO3 - UE3) * (UO3 - UE3) + ((UNE3 - USE3) / 2.0) * ((UNE3 - USE3) / 2.0));
				Uw3 = sqrt((UO3 - UW3) * (UO3 - UW3) + ((UNW3 - USW3) / 2.0) * ((UNW3 - USW3) / 2.0));
				Us3 = sqrt((UO3 - US3) * (UO3 - US3) + ((USE3 - USW3) / 2.0) * ((USE3 - USW3) / 2.0));

				Wn1 = Kn1 / sqrt(Un1 * Un1 + a * a);
				We1 = Ke1 / sqrt(Ue1 * Ue1 + a * a);
				Ww1 = Kw1 / sqrt(Uw1 * Uw1 + a * a);
				Ws1 = Ks1 / sqrt(Us1 * Us1 + a * a);

				Wn2 = Kn2 / sqrt(Un2 * Un2 + a * a);
				We2 = Ke2 / sqrt(Ue2 * Ue2 + a * a);
				Ww2 = Kw2 / sqrt(Uw2 * Uw2 + a * a);
				Ws2 = Ks2 / sqrt(Us2 * Us2 + a * a);

				Wn3 = Kn3 / sqrt(Un3 * Un3 + a * a);
				We3 = Ke3 / sqrt(Ue3 * Ue3 + a * a);
				Ww3 = Kw3 / sqrt(Uw3 * Uw3 + a * a);
				Ws3 = Ks3 / sqrt(Us3 * Us3 + a * a);

				Hon1 = Wn1 / (Wn1 + We1 + Ww1 + Ws1 + lambda);
				Hoe1 = We1 / (Wn1 + We1 + Ww1 + Ws1 + lambda);
				How1 = Ww1 / (Wn1 + We1 + Ww1 + Ws1 + lambda);
				Hos1 = Ws1 / (Wn1 + We1 + Ww1 + Ws1 + lambda);

				Hon2 = Wn2 / (Wn2 + We2 + Ww2 + Ws2 + lambda);
				Hoe2 = We2 / (Wn2 + We2 + Ww2 + Ws2 + lambda);
				How2 = Ww2 / (Wn2 + We2 + Ww2 + Ws2 + lambda);
				Hos2 = Ws2 / (Wn2 + We2 + Ww2 + Ws2 + lambda);

				Hon3 = Wn3 / (Wn3 + We3 + Ww3 + Ws3 + lambda);
				Hoe3 = We3 / (Wn3 + We3 + Ww3 + Ws3 + lambda);
				How3 = Ww3 / (Wn3 + We3 + Ww3 + Ws3 + lambda);
				Hos3 = Ws3 / (Wn3 + We3 + Ww3 + Ws3 + lambda);

				Hoo1 = lambda / (Wn1 + We1 + Ww1 + Ws1 + lambda);
				Hoo2 = lambda / (Wn2 + We2 + Ww2 + Ws2 + lambda);
				Hoo3 = lambda / (Wn3 + We3 + Ww3 + Ws3 + lambda);
				
				input_array.at<cv::Vec3f>(row, col)[0] = (Hon1 * UN1 + Hoe1 * UE1 + How1 * UW1 + Hos1 * US1 + Hoo1 * UO1);
				input_array.at<cv::Vec3f>(row, col)[1] = (Hon2 * UN2 + Hoe2 * UE2 + How2 * UW2 + Hos2 * US2 + Hoo2 * UO2);
				input_array.at<cv::Vec3f>(row, col)[2] = (Hon3 * UN3 + Hoe3 * UE3 + How3 * UW3 + Hos3 * US3 + Hoo3 * UO3);
				output_array.at<cv::Vec3f>(row, col)[0] = input_array.at<cv::Vec3f>(row, col)[0];
				output_array.at<cv::Vec3f>(row, col)[1] = input_array.at<cv::Vec3f>(row, col)[1];
				output_array.at<cv::Vec3f>(row, col)[2] = input_array.at<cv::Vec3f>(row, col)[2];
			}
			printf("%d\n", iter);
		}
	}
}


/*
	Save the inpainting domain to dinamic vector
*/
std::vector<Coord> create_mask(cv::Mat& mask)
{
	std::vector<Coord> mask_data;
	for (int i = 2; i < mask.rows - 2; i++)
	{
		for (int j = 2; j < mask.cols - 2; j++)
		{
			if (mask.at<cv::Vec3b>(i, j)[0] != 0)
			{
				Coord xy;
				xy.i = i;
				xy.j = j;
				xy.color = PIXEL_WHITE;
				mask_data.push_back(xy);
			}
		}
	}
	return mask_data;
}

测试图:

 

posted @ 2021-03-20 21:22  司砚章  阅读(264)  评论(0编辑  收藏  举报