Ask Your Question
0

Compare pixel value with threshold in Java

asked 2013-12-10 12:21:28 -0600

DonCossack gravatar image

updated 2013-12-10 12:22:05 -0600

Dear.

As some algorithm requires, e.g Harris corner detection, it is necessary to compare pixel value with a defined threshold. I know that in C++ it can be done quickly with command

if(image.at<float>(i,j) > int thres){}

But I have some problems doing it in Java, as I found only one command is

double [] pixel=image.get(int i, int j);

Could you please let me know how to perform comparision in this case?

Or in the doc of opencv, it is stated that the output could be int if

int pixel= image.get(int i, int j, byte[] data);

but I am not sure what to do with the parameter byte[] data.

Regards

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-12-11 00:07:09 -0600

There is ready function in OpenCV for that. In C++ it is cv::threshold in Java it is imgproc.threshold. There is reference manual for the C++ function here. Approximately the same description is added for Java version in OpenCV Javadoc.

edit flag offensive delete link more

Comments

Yes, it is true, the function is handy. However there is one thing that is, all the value which is smaller than threshold is put to zero. In my case I only want to "locate" the point which is smaller than threshold.

DonCossack gravatar imageDonCossack ( 2013-12-11 01:52:57 -0600 )edit

You can use threshold output as mask for other OpenCV functions.

Alexander Smorkalov gravatar imageAlexander Smorkalov ( 2013-12-11 02:25:52 -0600 )edit

Thanks.

I already did that, it is takes 2 steps more but anyhow it is still O.K. :D

DonCossack gravatar imageDonCossack ( 2013-12-11 07:53:59 -0600 )edit

Question Tools

Stats

Asked: 2013-12-10 12:21:28 -0600

Seen: 510 times

Last updated: Dec 11 '13