Ask Your Question

user1446598's profile - activity

2018-05-12 11:42:56 -0500 received badge  Popular Question (source)
2017-08-22 04:35:40 -0500 received badge  Famous Question (source)
2015-10-09 08:35:22 -0500 received badge  Notable Question (source)
2015-02-12 17:34:09 -0500 received badge  Famous Question (source)
2014-08-21 08:53:25 -0500 received badge  Popular Question (source)
2014-05-14 00:25:27 -0500 received badge  Notable Question (source)
2014-03-27 02:02:21 -0500 received badge  Good Question (source)
2014-02-03 10:57:00 -0500 received badge  Popular Question (source)
2013-08-29 09:46:33 -0500 received badge  Nice Question (source)
2013-06-09 14:09:30 -0500 answered a question How to save only ROI pixels in a Mat using a binary mask?

Thanks for the answers and comments, they have been useful.

The problem has been resolved by iterating over the image's pixels manually and keeping only those where the mask's bit is set to white.

I've tried this before but it didn't work. What I've noticed to be the reason, if not other factors as well:

  • The binary mask was at one point converted to RGB and then back to a grayscale image (before going through the method that selects ROI pixels). I think this might have been the reason why pixels had values near, but not exactly to, black and white intensity values. For eg. black was not 0, but was 16. I thus used pixels within a certain proximity to the actual expected white colour of 255.
  • I also had a logical error in the code where I iterated over the pixels of the single-channel mask, as opposed to the three-channel image. This was noticed upon receiving values only for the first channel after colour quantisation.

    The two above points seemed to help with more reasonable results. Perhaps there is a better way, and perhaps this method is not completely error-free, it hasn't been tested enough, but hope it would be useful for someone facing similar bugs.

    The Mat object that contained the ROI pixels is not suitable for display where the pixels are not ordered as in the original image. It merely provides a container for all the available colour pixels, which is convenient for the quantisation method.

2013-06-06 05:09:39 -0500 asked a question How to save only ROI pixels in a Mat using a binary mask?

I have the binary mask of an image, in a Mat object. I want to pass only the ROI (Region Of Interest) pixels (set to white in binary mask), without the background (that is set to black in the binary mask) to a colour-quantisation module. Question is how?

I have tried the copyTo method, but it adds the ROI to a new Mat, which is by default set to black. The black pixels are then considered in the colour quantization module, unlike what is intended (those are not ROI pixels).

Bounded rectangles, as far as I understand (have not tried), have the disadvantage of potentially adding extra background pixels that are not needed, as well as finding reasonable boundary values, which is not preferred in this case.

Any idea how to save a Mat with only the pixels needed (set) from a binary mask? It's the pixels that matter, thus it's fine if the image is reshaped, provided only ROI pixels are stored. It's a common CV problem, but I am yet to find a solution that worked.

I'm using OpenCV on Android (Java API), but it's the technique that matters the most (hopefully, if possible, with OpenCV example code for better understanding), that should be cross-platform.

Thank you in advance.

2013-05-26 11:09:48 -0500 asked a question Obtaining nearest neighbors using knn on Android

There's a question here that asks about how to obtain the nearest neighbors using knn, which as far as I know could be retreived using the optional parameter neighbors. However, on Android, OpenCV doesn't offer the neighbors parameter, as can be seen in its documentation here), the function's signature is as follows:

public float find_nearest(Mat samples, int k, Mat results, Mat neighborResponses, Mat dists)

As far as I know, I don't suppose the distances values, dists, are useful to reverse engineer into finding the actual neighbors' parameters.

Is there a certain way to obtain the neighbors original values, in Android, without using Android NDK - just using the java API?

Thank you in advance.

2013-03-31 10:46:45 -0500 commented answer Colour Quantization

Thanks for the detailed answer. If possible though; can some documentation be added to the code to highlight the key tasks for further elaboration?

2013-03-13 17:04:21 -0500 answered a question Best way to store a Mat object in Android

Thank you for the answers and comments. I prefer not to use Android NDK at the moment, and thus have tried saving Mat objects as Bitmap images. A boolean variable would be set (and amended) via Android's SharedPreferences class to signify whether the data needs to be read from the phone's storage as .Bmp (already saved), or need to be processed from scratch (which should, ideally, be only once).

  • To convert from Bmp to Mat, check this) OpenCV method, bitmapToMat.
  • To convert from Mat to Bmp, check this) OpenCV method, matToBitmap.

I still need to try this method in more depth, but I think it should offer a reasonable alternative.

2013-03-10 16:54:40 -0500 received badge  Student (source)
2013-03-10 15:24:28 -0500 asked a question Best way to store a Mat object in Android

What is the best way to store a Mat object in Android? (there is a similar, unanswered, question here)

In image processing apps; it requires quite a lot of processing time to perform necessary pipelines which could be redundant. Thus, Mats would be preferably stored to prevent re-computation every time. I considered using SQLlite databases, but those seem to add unnecessary complexity in reading and writing Mat objects, where the method I understand would be writing each individual pixel in a Mat object in a separate row.

I came across solutions (regarding saving custom classes, not OpenCV in specific) that suggested saving the file externally to the SD card. That seems quite plausible, but the problem is that class Mat must implement Serializable class (according to many online references, as here), which is not the case. I don't wish to alter OpenCV's library albeit being open source, because I don't have much experience around the library.

Are there any time, and memory, efficient ways to preserving Mat objects for later launches of the app?

Thank you for your time.

2013-03-10 12:52:17 -0500 received badge  Scholar (source)
2013-03-10 12:52:04 -0500 received badge  Supporter (source)
2013-03-10 12:51:16 -0500 commented answer How to get and modify the pixel of Mat in Java?

Thanks for the answer. However I don't quite understand the use of the byte array. I tried, based on the above suggestion, using m.get(0, 0, buff), and m.get(0,0)[0] (for a grayscale image). The latter resulted in the expected value; the former however (using the byte array) gave a large value (exceeding 255) that I don't understand. My image is of type CV_8U.

2013-03-10 01:34:29 -0500 asked a question Accessing pixels in Mat using Android (Java API)

I am trying to access pixels' intensity values in Mat objects (image mats and histogram mats to be specific; such as gray scale value in gray scale images) and am unsure how to do so using the Java API (not NDK).

  • In C++, it could be done as so; mat.at<float>(i,j)
  • In the OpenCV Java API) there is a get(int row, int col) method, but it returns a double[]; I am unsure what this array includes, my assumption it includes each channel's value (in the given color type's order) in that very (row, col) location but could not find verifying detail in the docs.

In short; how do I access a pixel's intensity value in a Mat (single or multi-channel) using the OpenCV Java API in Android?