cvDistTransform get invert data why

i want to get distance data from pictures so i use cvDistTransform ( i am using opencv ), but my output was inverted the black color back white and white back black

my source code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <opencv.hpp>
#include <iostream>
#include <Windows.h>
using namespace std ;


void main()
{
    ::IplImage *Src = cvLoadImage ( "parthenon.jpg" , CV_LOAD_IMAGE_GRAYSCALE) ;
    ::IplImage *Src2 = cvLoadImage ( "parthenon.jpg" ) ;


    if ( Src->depth == IPL_DEPTH_8U)
    {       
        cout << "input ok" << endl << endl ;
    }

    ::IplImage *Distance = cvCreateImage ( ::cvGetSize ( Src) , IPL_DEPTH_32F, Src->nChannels);

    cvThreshold(Src,Src ,90,90,CV_THRESH_BINARY); 

    ::cvDistTransform ( Src , Distance ,CV_DIST_L2 , CV_DIST_MASK_PRECISE , NULL , NULL  );


    cvConvertScale( Distance, Distance,5000.0);
    ::cvScale ( Distance , Distance , 5 );

    ::cvNamedWindow ("SRC" , CV_WINDOW_NORMAL );
    ::cvNamedWindow ("HIST" , CV_WINDOW_NORMAL );

    ::cvSaveImage ( "Distance.jpg" , Distance );
    while (1)
    {
        ::cvShowImage ( "SRC" , Src2);
        ::cvShowImage ( "HIST" , Distance);

        ::cvWaitKey(0);
    }

    ::cvDestroyAllWindows();
    ::cvReleaseData(Src);


    ::system ("pause");
}



source image :

http://imageshack.us/photo/my-images/72/parthenonh.jpg/

output :

http://i39.tinypic.com/2uik9if.jpg

the output should like this:

http://i41.tinypic.com/343szeo.jpg
Last edited on
Topic archived. No new replies allowed.