Beispiel #1
0
//-------------------------------------------
// マトリックスの転置と積.
// 左集合転置版.
//-------------------------------------------
// c = 結果行列の先頭アドレス.
// a,b = 掛ける行列の先頭アドレス.
// l = a の列数.
// m = a の行数、b の行数.
// n = b の列数.
//-------------------------------------------
void matrix_left_transpose_x(double *c, const double *a, const double *b, const int l, const int m, const int n)
{
	double *t = new double[l * m];
	matrix_init_zero(t, l, m);

	matrix_transpose(a, t, l, m);

	matrix_x(c, t, b, l, m, n);

	delete[] t;
	t = NULL;
}
Beispiel #2
0
//-------------------------------------------
// マトリックスの転置と積.
// 右集合転置版.
//-------------------------------------------
// c = 結果行列の先頭アドレス.
// a,b = 掛ける行列の先頭アドレス.
// l = a の行数.
// m = a の列数、b の列数.
// n = b の行数.
//-------------------------------------------
void matrix_right_transpose_x(double *c, const double *a, const double *b, const int l, const int m, const int n)
{
	double *t = new double[n * m];
	matrix_init_zero(t, n, m);

	matrix_transpose(b, t, n, m);

	matrix_x(c, a, t, l, m, n);

	delete[] t;
	t = NULL;
}
Beispiel #3
0
int GaussianBlur::processFrame(const string &writer_id, shared_ptr<const
        VideoFrame> frame)
{
    LogDebug2("Applying gaussian blur on frame " << frame->getId());
    FrameMatrix matrix(frame);

    //TODO/FIXME DC: Currently ignoring edges
    VideoFrame *blurred_frame = new VideoFrame(frame->getId(),
            frame->getWidth() - (m_dist_x * 2), frame->getHeight() - (m_dist_y * 2));

    uint counter = 0;

    //Implementation note: pass as result reference to avoid a ton of
    //mallocs
    Matrix<uint> matrix_x(m_weight_matrix_x->getX(), m_weight_matrix_y->getY());
    Matrix<uint> matrix_y(m_weight_matrix_x->getX(), m_weight_matrix_y->getY());

    //TODO/FIXME DC: Currently ignoring edges
    for(uint y = m_dist_y; y < matrix.getY() - m_dist_y; y++)
    {
        for(uint x = m_dist_x; x < matrix.getX() - m_dist_x; x++)
        {
            //do some fancy math to not get out of bounds and set the
            //middle as origin
            uint x_start    = x - m_dist_x;
            uint y_start    = y - m_dist_y;
            uint x_end      = x + m_dist_x;
            uint y_end      = y + m_dist_y;

            matrix.multiplyFrameMatrixPart(x_start, x_end, y_start, y_end,
                    *m_weight_matrix_x, matrix_x);
            matrix.multiplyFrameMatrixPart(x_start, x_end, y_start, y_end,
                    *m_weight_matrix_y, matrix_y);

            Matrix<uint> matrix_added = matrix_x + matrix_y;
            uint8_t value = matrix_added.getTotal()/2;

            blurred_frame->getLumaData()[counter] = value;
            counter = counter + 1;
        }
    }

    addFrame(blurred_frame);
    return 0;
}
Beispiel #4
0
void factorize(double *v, int row, int col, int features, unsigned int count, MatrixFactor *mf)
{

	// 重みの行列と特徴の行列をランダムな値で初期化.
	double * h = new double[features * col];
	double * hn = new double[features * col];
	double * hd = new double[features * col];
	double * hd_t = new double[features * features];
	double * w = new double[row * features];
	double * wn = new double[row * features];
	double * wd = new double[row * features];
	double * wd_t = new double[row * col];

	// 重みと特徴の乗算結果用行列.
	double * wh = new double[row * col];

	matrix_init_zero((double*)wh, row, col);

	matrix_init(h, features, col);
	matrix_init_zero(hn, features, col);
	matrix_init_zero(hd, features, col);
	matrix_init_zero(hd_t, features, features);
	matrix_init(w, row, features);
	matrix_init_zero(wn, row, features);
	matrix_init_zero(wd, row, features);
	matrix_init_zero(wd_t, row, col);


	//matrix_print((double*)h, features, col);
	//matrix_print((double*)w, raw, features);

	unsigned int i = 0;
	for (i = 0; i < count; i++){

		// 特徴の重みの行列の積から、元データとの差を計算する.
		matrix_x(wh, w, h, row, features, col);
		int cost = matrix_diff(v, wh, row, col);

		// 差が完全にゼロになったらループを抜ける.
		if (cost == 0){
			break;
		}

		//-------------------------------------------------------------------------------------------
		// 特徴の行列を更新する.
		//-------------------------------------------------------------------------------------------
		// hn 転置した重みの行列にデータ行列を掛け合わせたもの
		matrix_tx_left(hn, w, v, features, row, col);

		// hd  転置した重みの行列に重みの行列を掛け合わせたものに特徴の行列を掛け合わせたもの
		matrix_tx_left(hd_t, w, w, features, row, features);
		matrix_x(hd, hd_t, h, features, features, col);


		matrix_x(h, h, hn, features, col);
		matrix_divide(h, h, hd, features, col);



		//-------------------------------------------------------------------------------------------
		// 重みの行列を更新する.
		//-------------------------------------------------------------------------------------------

		// wn  データ行列に転置した特長の行列を掛け合わせたもの.
		matrix_tx_right(wn, v, h, row, col, features);

		// wd  重みの行列に、特徴の行列を掛け合わせたものに転置した特長の行列を掛け合わせたもの.
		matrix_x(wd_t, w, h, row, features, col);
		matrix_tx_right(wd, wd_t, h, row, col, features);

		matrix_x(w, w, wn, row, features);
		matrix_divide(w, w, wd, row, features);

	}

	mf->h = h;
	mf->w = w;


	//matrix_x(wh, w, h, ROW, FEATURES, COL);
	//matrix_print(wh, ROW, COL);
	//matrix_print(w, ROW, FEATURES);
	//matrix_print(h, FEATURES, COL);

	delete[] hn;
	delete[] hd;
	delete[] hd_t;
	delete[] wn;
	delete[] wd;
	delete[] wd_t;
	delete[] wh;
}