Ask Your Question
1

How to use norm with Java?

asked 2018-08-29 13:15:23 -0600

accdev gravatar image

I have a code that is written in both Python and C++ that I am now converting to Java. I use the norm function to compare 2 points of an RGB image. In Python and C++ getting these pixel values is simple, and you can just plug them into the norm function. In java, when getting these values the data type changes from Mat to double[] array. The norm function however takes Mat as its arguments. Is it possible to convert the double array to Mat, or to get the pixel values as a Mat?

This is the current methods I am using:

double[] right_pt = image_to_read.get(middlexint+radiint, middleyint); // get pixel value point1
double[] pti = image_to_read.get(middlexint+radiint-i,middleyint);    // get pixel value point2
double e_dist = Core.norm(right_pt, pti);  // calculate euclidean distance
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-08-30 00:14:57 -0600

berak gravatar image

updated 2018-08-30 00:18:35 -0600

well, the java wrappers are indeed somewhat clumsy here (compared to c++),

but you could either work around it with 1-pixel Mat's like:

Mat left  = img.submat(yleft,  yleft+1,  xleft,  xleft+1);
Mat right = img.submat(yright, yright+1, xright, xright+1);
double dist = Core.norm(left, right);

or just compute it manually:

double db = right_pt[0] - pti[0];
double dg = right_pt[1] - pti[1];
double dr = right_pt[2] - pti[2];
double dist = Math.sqrt(db*db + dg*dg + dr*dr);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-08-29 13:15:23 -0600

Seen: 2,374 times

Last updated: Aug 30 '18