-1
$\begingroup$

I am trying to create a histogram of the depth videos (converted to grayscale first) in order to apply a threshold to keep only highest values, and then do some dilation in order to extract contours. Apparently I am stuck, and besides that i don't know if what I am thinking is the right way to extract contours from depth videos.

In the following code I got stuck in the point of applying the threshold. I think that iam applying it in the wrong way. Which is the correct to apply a threshold in this situation in order to obtain a black and white image?

Any suggestions or tutorials would be awesome!!!

Thank you very much!

int bins = 256;
int hsize[] = {bins};

//max and min value of the histogram
float max_value = 0, min_value = 0;

float value;
int normalized;

//ranges - grayscale 0 to 256
float xranges[] = { 0, 256 };
float* ranges[] = { xranges };

//image is the actual source from input depth video
gray = cvCreateImage( cvGetSize(image), 8, 1 );
cvCvtColor( image, gray, CV_BGR2GRAY );

cvNamedWindow("original",1);
cvNamedWindow("gray",1);
cvNamedWindow("histogram",1);
cvNamedWindow("black & white",1);

IplImage* planes[] = { gray };

//get the histogram and some info about it
hist = cvCreateHist( 1, hsize, CV_HIST_ARRAY, ranges,1);
cvCalcHist( planes, hist, 0, NULL);
cvGetMinMaxHistValue( hist, &min_value, &max_value);
printf("min: %f, max: %f\n", min_value, max_value);

imgHistogram = cvCreateImage(cvSize(bins, image->height),8,1);
cvRectangle(imgHistogram, cvPoint(0,0), cvPoint(256,image->height), CV_RGB(255,255,255),-1);

 //I think that here i have messed up things :( Any suggestions ???
bw_img = cvCreateImage(cvGetSize(imgHistogram), IPL_DEPTH_8U, 1);
cvThreshold(imgHistogram, bw_img, 150, 255, CV_THRESH_BINARY);

//draw the histogram
for(int i=0; i < bins; i++){
        value = cvQueryHistValue_1D( hist, i);
        normalized = cvRound(value*image->height/max_value);
        cvLine(imgHistogram,cvPoint(i,image->height), cvPoint(i,image->height-normalized), CV_RGB(0,0,0));
}

//show the image results
cvShowImage( "original", image );
cvShowImage( "gray", gray );
cvShowImage( "histogram", imgHistogram );
cvShowImage( "balck & white", bw_img);

Images showing the step processes 1) source video input ( http://imageshack.us/photo/my-images/823/sourcevideo.jpg/ ) 2) gray-scale video ( http://imageshack.us/photo/my-images/23/grayscalei.jpg/ ) 3) binary video ( http://imageshack.us/photo/my-images/684/binaryi.jpg/ ) 4) final contour output ( http://imageshack.us/photo/my-images/35/finaloutput.jpg/ )

The images show what i would like to accomplish but for depth videos. I got problem obtaining the binary video. I have create a histogram and i haven't found a way to apply threshold in order to obtain highest pixel values and to transform the video to black and white.


First of all, what i am asking is what are right steps to extract contours from depth videos and if my approach is correct or not as described below??

1) grayscale an image 2) create histogram 3) apply threshold to convert to black and white image and keep only highest pixel values 4) (dilation/erosion) depends on the black and white image 5) find contours on the black and white image

Second of all, my prolem is how can i create a binary(black and white image) with only the highest values retrived from the histogram of a gray-scale image??? I think that I am applying it the wrong way because i don't get the expected result (black & white image), the only thing i get is a totaly black image and nothing else.

Third of all, i have put the code to make things more clear and not vaguely.

Thanks in advance!

$\endgroup$
  • 3
    $\begingroup$ Welcome to dsp.SE. Your question is not clear. Dumping a pile of code and vaguely saying that you're "stuck" is not going to yield a lot of meaningful responses. Why do you think you're applying the threshold in the wrong way? What specifically are you stuck on? You should probably frame the problem more theoretically; it's possible that there could be someone who could have a good answer to your question, but can't/won't read your pile of C code. $\endgroup$ – Jason R Jan 5 '12 at 19:35
  • $\begingroup$ Can you put some images here that we can understand the context? I will try to help you as best i can! $\endgroup$ – Dipan Mehta Jan 6 '12 at 15:26
  • $\begingroup$ Please do not write your updates as answers. I understand that you probably lost access to your account because you cleared your cookies. I've merged all your new accounts into this one and you should be able to edit your post to include your updates. You can avoid all of these by simply registering an account. I've approved your edit & appended your answer below as an edit, but your question overall needs a LOT of editing and clarifications, before it can be answered. Please try to follow Jason R's advice in rephrasing your question. $\endgroup$ – Lorem Ipsum Jan 6 '12 at 18:45
1
$\begingroup$

As a general approach, your steps are okay. However, your results quite a bit depends on the efficacy of thresholding. However, this can be tricky and results may vary from image to image.

I would suggest best of the threshold algorithm can be otsu's algorithm http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.