Exemple #1
0
vector <CENTR_VECT>  init_centriod (size_t cluster_number, vector <GDB> inGDB) {

	CENTR_VECT CV;
	vector <CENTR_VECT> CENTR;
	size_t j = 0;

	if ((inGDB.at(0).DATAGROUP == "STRIAE") || (inGDB.at(0).DATAGROUP == "SC")) {

		do {

			srand(j + 2);

			CV.U = rand();

			CV.U = rand();		CV.U = (CV.U / RAND_MAX) * 2.0 - 1.0;
			CV.V = rand(); 		CV.V = (CV.V / RAND_MAX) * 2.0 - 1.0;
			CV.W = rand(); 		CV.W = (CV.W / RAND_MAX);
			CV.X = rand(); 		CV.X = (CV.X / RAND_MAX) * 2.0 - 1.0;
			CV.Y = rand(); 		CV.Y = (CV.Y / RAND_MAX) * 2.0 - 1.0;
			CV.Z = rand(); 		CV.Z = (CV.Z / RAND_MAX);

			CV = unitvector (CV);
			CENTR.push_back(CV);
			j++;

		} while (j < cluster_number + 1);
	}

	else {

		do {

			srand(j + 2);

			CV.U = rand();

			CV.U = rand();			CV.U = (CV.U / RAND_MAX) * 2.0 - 1.0;
			CV.V = rand();			CV.V = (CV.V / RAND_MAX) * 2.0 - 1.0;
			CV.W = rand();			CV.W = (CV.W / RAND_MAX);
			CV.X = 0.0;
			CV.Y = 0.0;
			CV.Z = 0.0;

			CV = unitvector (CV);

			CENTR.push_back(CV);
			j++;

		} while (j < cluster_number + 1);
	}

	return CENTR;
}
Exemple #2
0
vector <CENTR_VECT> compute_centroid_from_which_group (size_t cluster_number, vector <int> which_group, vector <GDB> inGDB) {

	size_t j = 0;
	size_t k = 0;

	size_t record_number = inGDB.size();
	vector <CENTR_VECT> new_centroid;
	CENTR_VECT CV;

	do {

		CV = declare_vector (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
		new_centroid.push_back(CV);
		j++;

	} while (j < cluster_number);

	j = 0;

	do {

		do {

			if ((which_group.at(k)) == j) {

				if ((inGDB.at(0).DATAGROUP == "STRIAE") || (inGDB.at(0).DATAGROUP == "SC")) {

					new_centroid.at(j).U = new_centroid.at(j).U + inGDB.at(k).N.X;
					new_centroid.at(j).V = new_centroid.at(j).V + inGDB.at(k).N.Y;
					new_centroid.at(j).W = new_centroid.at(j).W + inGDB.at(k).N.Z;
					new_centroid.at(j).X = new_centroid.at(j).X + inGDB.at(k).SV.X;
					new_centroid.at(j).Y = new_centroid.at(j).Y + inGDB.at(k).SV.Y;
					new_centroid.at(j).Z = new_centroid.at(j).Z + inGDB.at(k).SV.Z;
				}

				else {

					new_centroid.at(j).U = new_centroid.at(j).U + inGDB.at(k).N.X;
					new_centroid.at(j).V = new_centroid.at(j).V + inGDB.at(k).N.Y;
					new_centroid.at(j).W = new_centroid.at(j).W + inGDB.at(k).N.Z;
				}
			}

			k++;

		} while (k < record_number);

		new_centroid.at(j) = unitvector (new_centroid.at(j));

		k = 0;
		j++;

	} while (j < cluster_number);

	return new_centroid;
}
Exemple #3
0
void main()
{
	define_cameraInfo(cameraInfomation);
	mat H_rel_abs(5, 5);
	mat H_abs_phi(5, 5);
	mat H_phi_sphi(5, 5);
	mat H_T(5, 5);
	mat H_M(5, 5);
	mat H_sphi_phi(5, 5);

	define_H(H_rel_abs, H_abs_phi, H_phi_sphi, H_T, H_M, H_sphi_phi, cameraInfomation);

	mat sol(5, 1, fill::zeros);
	
	mat input(5, 1);
	//--------------------------------------------------------------------------
	int lens = cameraInfomation.K;//마이크로렌즈갯수
	int sensor = cameraInfomation.N;//마이크로레즈 한개당 센서 갯수
	mat imageCoord(4, 3);
	imageCoord <<0 << 0 << 2000 << endr
		<< 0 << 1000 << 2000 << endr
		<< 1000 << 1000 << 2000 << endr
		<< 1000 <<1000 << 2000 << endr;
	int world_x = 1000, world_y = 1000; //이미지 크기
	int input_width, input_height;
	colorimg** inputimg = ReadImage_color("C:\\Users\\김송란\\Documents\\GitHub\\Study\\lightfield\\cat.jpg", &input_width, &input_height);
	mat Pl1(1, 3), Pl2(1, 3); //s,t,u,v 저장할 변수
	mat unitvector(1, 3);
	mat Pp1(1, 3), Pp2(1, 3), Pp3(1, 3); //평면의 모서리 3개 좌표 변수
	mat nomalvector(1, 3); //법선벡터
	mat x(1, 3);//직선과 평면이 만나는 점
	colorimg** outimg = (colorimg**)IntAlloc2(lens*sensor, lens*sensor);
    colorimg** SubApertureImg = (colorimg**)IntAlloc2(lens*sensor, lens*sensor);
	mat a, b, c, d, sub_xy;
	int InOutFlag = 0;                           
	for (int k = 0; k < lens; k++)
	{
		for (int l = 0; l < lens; l++)
		{
			for (int i = 0; i < sensor; i++)
			{
				for (int j = 0; j < sensor; j++)
				{
					input << i << endr
						<< j << endr
						<< k << endr
						<< l << endr
						<< 1 << endr;
					sol = H_sphi_phi * H_M * H_T * H_phi_sphi * H_abs_phi * H_rel_abs *input;
					//cout << "행렬 원소 보기: " << endl << sol << endl;
					LineEquation(sol(0,0), sol(1,0), sol(2,0), sol(3,0), cameraInfomation.D, Pl1, Pl2, unitvector);//직선의 방정식
					PlaneEquation(imageCoord, Pp1, Pp2, Pp3, nomalvector); //이미지평면의 방정식
					CrossLinePlane(unitvector, nomalvector, Pp1, Pl1, x); //직선과 이미지평면이 만나는 점
					InterpolationCoor(x, a, b, c, d, sub_xy, input_width, input_height, world_x, world_y); //선형보간법 좌표 생성
					InOutFlag=detectInOut(imageCoord, x);
					rawimage(InOutFlag,sensor*k+i,sensor*l+j,input_width,input_height, inputimg, outimg, a, b, c, d, sub_xy);		//이미지생성
				}
			}

		}

	}
	
	for (int i = 0; i < sensor; i++)
	{
		for (int j = 0; j < sensor; j++)
		{
			MakeSubApertureImages(i, j, lens, sensor, outimg, SubApertureImg);
		}

	}
	

	WriteImage_color("C:\\Users\\김송란\\Documents\\GitHub\\Study\\lightfield\\영상출력테스트5.bmp", outimg, lens*sensor, lens*sensor);
	WriteImage_color("C:\\Users\\김송란\\Documents\\GitHub\\Study\\lightfield\\영상출력테스트sub5.bmp", SubApertureImg, lens*sensor, lens*sensor);

	
	
	

}