This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Converting MATLAB Code into Eigen - Manipulation of Arrays

Tags: matlab, arrays, matrices, map matlab, arrays, matrices, map matlab, arrays, matrices, map
(comma "," separated)
Royi
Registered Member
Posts
34
Karma
0
Hello,
I'm really a new user of Eigen (And programming in C / C++ in general).
I have simple MATLAB code I'd like some assistance with just as first step guidance.

Code: Select all

NUM_ROWS = 96;
NUM_COLS = 88;

% Random Indices (In real code will be a pre defined array)
vRandPxIdx = randperm(NUM_ROWS * NUM_COLS);
vRandPxIdx = vRandPxIdx(:);

mRefImageR = randn(NUM_ROWS, NUM_COLS);
mRefImageG = randn(NUM_ROWS, NUM_COLS);
mRefImageB = randn(NUM_ROWS, NUM_COLS);

% Here is the actual code
vImageRGradX = mRefImageR(:, 1:(NUM_COLS - 1)) - mRefImageR(:, 2:NUM_COLS);
vImageRGradY = mRefImageR(1:(NUM_ROWS - 1), :) - mRefImageR(2:NUM_ROWS, :);
vImageGGradX = mRefImageG(:, 1:(NUM_COLS - 1)) - mRefImageG(:, 2:NUM_COLS);
vImageGGradY = mRefImageG(1:(NUM_ROWS - 1), :) - mRefImageG(2:NUM_ROWS, :);
vImageBGradX = mRefImageB(:, 1:(NUM_COLS - 1)) - mRefImageB(:, 2:NUM_COLS);
vImageBGradY = mRefImageB(1:(NUM_ROWS - 1), :) - mRefImageB(2:NUM_ROWS, :);

vImageRGradX = vImageRGradX(:);
vImageRGradY = vImageRGradY(:);
vImageGGradX = vImageGGradX(:);
vImageGGradY = vImageGGradY(:);
vImageBGradX = vImageBGradX(:);
vImageBGradY = vImageBGradY(:);

% Size actually known in compilation time
mPixelPairs = [vImageRGradX, vImageGGradX, vImageBGradX; ...
    vImageRGradY, vImageGGradY, vImageBGradY; ...
    (mRefImageR(:) - mRefImageR(vRandPxIdx)), (mRefImageG(:) - mRefImageG(vRandPxIdx)), (mRefImageB(:) - mRefImageB(vRandPxIdx))];

vPairDist       = sum(abs(mPixelPairs), 2) / 3;

% PAIR_DIST_THR is predefined scalar
vInvlaidPairIdx = vPairDist < PAIR_DIST_THR;

vPairDist(vInvlaidPairIdx)      = [];
mPixelPairs(vInvlaidPairIdx, :) = [];

vPairDist = vPairDist ./ max(vPairDist);

vTransformedPx  = abs(mPixelPairs * mWeightsCom.');
vEnergyFunction = sum(abs(vTransformedPx - vPairDist));

[~, transIdx]   = min(vEnergyFunction);


How would write it in Eigen assuming 'mRefImageR', 'mRefImageG' and 'mRefImageB' are input to the function (Float arrays with known size as above).
So I must use the Map Object yet I'm not sure how.
I also not sure how to use indices as I'm using in MATLAB to set values of the arrays.

All arrays / matrices above have compile time fixed size.

Thank You.
Royi
Registered Member
Posts
34
Karma
0
Anyone?

At least the part of the indices:

Code: Select all

% Here is the actual code
vImageRGradX = mRefImageR(:, 1:(NUM_COLS - 1)) - mRefImageR(:, 2:NUM_COLS);
vImageRGradY = mRefImageR(1:(NUM_ROWS - 1), :) - mRefImageR(2:NUM_ROWS, :);
vImageGGradX = mRefImageG(:, 1:(NUM_COLS - 1)) - mRefImageG(:, 2:NUM_COLS);
vImageGGradY = mRefImageG(1:(NUM_ROWS - 1), :) - mRefImageG(2:NUM_ROWS, :);
vImageBGradX = mRefImageB(:, 1:(NUM_COLS - 1)) - mRefImageB(:, 2:NUM_COLS);
vImageBGradY = mRefImageB(1:(NUM_ROWS - 1), :) - mRefImageB(2:NUM_ROWS, :);



Thank You.


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]