Ask Your Question
0

Thresholding on a specific area of an image

asked 2015-01-07 05:47:09 -0600

jiarongkoh gravatar image

updated 2015-01-07 05:57:48 -0600

Hi everyone, I am working on an app using OpenCV249 on android and would like to perform thresholding on a specific area of an image. This specific area is specified by the user by doodling a yellow rectangle on the image. Once he/she has selected this area, thresholding will be performed on that yellow rectangle window only and then output the entire image on a new ImageView.

I've went through the bulk of the java docs and I can't seem to find any suitable methods that allows me to define that thresholding window unfortunately. Anyone any advise please? Do note that I am developing for android.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2015-01-07 15:54:12 -0600

updated 2015-01-07 16:59:37 -0600

Specific area of an image could be referenced as ROI, described in docs as:

// create a new 320x240 image
Mat img(Size(320,240),CV_8UC3);
// select a ROI
Mat roi(img, Rect(10,10,100,100));
// fill the ROI with (0,255,0) (which is green in RGB space);
// the original 320x240 image will be modified
roi = Scalar(0,255,0);

In Java it looks like:

Mat roi = img.submat(rowStart, rowEnd, colStart, colEnd);
edit flag offensive delete link more

Comments

1

hi @Vit, for additional bonus points, can you try to translate that to java ,

(and maybe even test it ?)

berak gravatar imageberak ( 2015-01-07 16:05:45 -0600 )edit
1

@berak last time I used OpenCV in Java ~1 year ago and afair it is submat(..) function. Answer updated.

Vit gravatar imageVit ( 2015-01-07 17:03:43 -0600 )edit

@Vit thanks for your reply, but I don quite get it. I did this:

source= Utils.loadResource(this.getApplicationContext(), R.drawable.tread);
destination = new Mat(source.rows(), source.cols(), source.type());
Mat roi = source.submat(10, 100, 10, 100);  
Imgproc.threshold(roi, destination, 50, 255, Imgproc.THRESH_BINARY_INV);
Highgui.imwrite("ThreshZero.jpg", destination);

But it shows me a blank image. I'm guessing that when I perform the thresholding on the Mat roi, it is defining the roi as one isolated complete image itself. How can I modify my code, any advise?

jiarongkoh gravatar imagejiarongkoh ( 2015-01-08 00:31:40 -0600 )edit
1

I can not test it in Java right now but guess roi size and destination size for threshold(..) must be the same. May be even threshold(roi, roi, ...) is correct ( then it will change only a part of source image ).

Vit gravatar imageVit ( 2015-01-08 04:16:04 -0600 )edit

Is anyone able to help? I tried the code above, basically thresholds the submat and imwrite as an isolated image itself. I need the complete image with that little portion threshold-ed only. Can anyone please advise?

jiarongkoh gravatar imagejiarongkoh ( 2015-01-09 01:30:29 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-07 05:47:09 -0600

Seen: 1,147 times

Last updated: Jan 07 '15