Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need an example how to use resample with RGB images #68

Open
vfateev opened this issue May 11, 2017 · 0 comments
Open

Need an example how to use resample with RGB images #68

vfateev opened this issue May 11, 2017 · 0 comments

Comments

@vfateev
Copy link

vfateev commented May 11, 2017

The description says the method works with single and multi channel.
So what I'm trying to do is smth like this:
// Prepare input data
var columns = imageData.width;
var rows = imageData.height;
var data_type = jsfeat.U8_t | jsfeat.C3_t; // RGB = 3 channels
var src = new jsfeat.matrix_t(columns, rows, data_type);

    var size = imageData.data.length;
    for (var i = 0, j = 0 ; i < size ; i +=4, j +=3) {
        src.data[j]     = imageData.data[i];
        src.data[j + 1] = imageData.data[i + 1];
        src.data[j + 2] = imageData.data[i + 2];
    }

    // Prepare output data
    var scale = 0.5;
    var nw = Math.floor(width * scale);
    var nh = Math.floor(height * scale);
    var dst = new jsfeat.matrix_t(nw, nh, data_type);

    // Resample
    jsfeat.imgproc.resample(src, dst, nw, nh);

    // Prepare output imageData
    var dstImageData = createEmptyImageData(nw, nh);
    size = dstImageData.data.length;

    for (i = 0, j = 0 ; i < size ; i += 4, j += 3) {
        dstImageData.data[i] = dst.data[j];
        dstImageData.data[i + 1] = dst.data[j + 1];
        dstImageData.data[i + 2] = dst.data[j + 2];
        dstImageData.data[i + 3] = 255;
    }
    
    // Draw dstImageData into the canvas and check

The result I got is pretty weird: https://www.dropbox.com/s/xfjucm99kjd6wpx/resample_result.jpg?dl=0
Can't figure out what is wrong, could you please help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant