Matlab and OpenCV4Android - different Mat dimensions [closed]

asked 2017-12-11 04:45:08 -0500

noamgot gravatar image

updated 2017-12-11 05:57:00 -0500

Ther's a piece of code I should translate from Matlab to OpenCV4Android. Part of this code takes and RGB image and splits it. When I run the Matlab app, I can see that each of the splitted channels is of type uint8 and the dimensions are 376x640. In that case, the image was loaded by imread , and split by simple matrix operations:

input_im = imread('Field.png');
R = input_im(:,:,1);
G = input_im(:,:,2);
B = input_im(:,:,3);

image description

When I run the Android app, after splitting the image (to RGBa first, it doesn't matter), I get that each channel is of type CV_8UC1 (which should be equivalent to uint8, If I'm getting it right), but the dimensions are 1128x1920 (which is multiplying the original dimensions by a factor of 3). The original image was with the same dimensions, but the type was CV_8UC4. The image was preloaded to an ImageView and was converted to Mat:

private Bitmap mBitmap;
private Mat mImToProcess;
// ...
mBitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();
Utils.bitmapToMat(mBitmap, mImToProcess);
// ...
List<Mat> chans = new ArrayList<>(mImToProcess.channels());
Core.split(mImToProcess, chans);

image description

I would like to now what makes this difference? And is there to work in my Android app with similar dimensions to the Matlab app.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2017-12-12 02:04:34.734380

Comments

can we see your code, doing that ?

berak gravatar imageberak ( 2017-12-11 05:10:00 -0500 )edit
1

I added it in the original question

noamgot gravatar imagenoamgot ( 2017-12-11 05:56:04 -0500 )edit

perfect, thanks !

which size has the bitmap ?

berak gravatar imageberak ( 2017-12-11 05:59:02 -0500 )edit

it says 1128x1920 (h x w) - https://ibb.co/mvbEhw

noamgot gravatar imagenoamgot ( 2017-12-11 06:22:19 -0500 )edit

so, there's nothing wrong with opencv's conversion, the problem is already in your imageView / bitmap.

you'll have to inquire, what you uploaded there, and how.

berak gravatar imageberak ( 2017-12-11 06:38:30 -0500 )edit

but how come the dimensions are different in the bitmap? in the Android app, the image is uploaded from the drawable directory, and it is the exact same image I use in my Matlab app

noamgot gravatar imagenoamgot ( 2017-12-11 07:04:31 -0500 )edit

sorry, i have no idea.

berak gravatar imageberak ( 2017-12-11 07:18:31 -0500 )edit

ok, thanks for your help anyway

noamgot gravatar imagenoamgot ( 2017-12-11 08:13:37 -0500 )edit