View Single Post
  #1 (permalink)  
Old March 3rd, 2005, 09:52 AM
ck ck is offline
Authorized User
 
Join Date: Dec 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default wat wrong of my code (image processing)

hi guys, i doing the image processing for my project..& week after next is my submission date..so, i really suffer, stress & tension...coz if i can't finish i will fail my project...hope some1 can & will help me thanks a lot...some i using OpenCV library to code,some is in C/C++ language...i stuck in thinning module which is thin the ridge in one-pixel thick...it contains 2 step, & this 2 steps got 4 conditions..if match the conditions, remove the contour point which is delete the pixel...in thinning it got 3*3 mask as below:

p9 p2 p3
p8 p1 p4
p7 p6 p5

1st step:
condition 1:
2<N(P1)<6
where N(P1) = p2+p3+p4+p5+p6+p7+p8+p9

condition 2:
T(P1) = 1
where T(P1) is transition 0 to 1 in order sequence p2, p3, p4...p9

condition 3:
p2, p4, p6 = 0,which mean this 3 position at least 1 is in 0, which is black color.

condition 4:
p4, p6, p8 = 0, which mean this 3 position at least 1 is in 0, which is black color.

if all the condition is match then delete the pixel.


step 2:
condition 1:
2<N(P1)<6
where N(P1) = p2+p3+p4+p5+p6+p7+p8+p9

condition 2:
T(P1) = 1
where T(P1) is transition 0 to 1 in order sequence p2, p3, p4...p9

condition 3:
p2, p4, p8 = 0,which mean this 3 position at least 1 is in 0, which is black color.

condition 4:
p2, p6, p8 = 0,which mean this 3 position at least 1 is in 0, which is black color.

if all the condition is match then delete the pixel.

so how to do it...i really dunno how..i used 1 month to fix it, but till now also not success...i really really hope got some1 will help me fix it...below is my code...hope correct for me...thanks...

//opencv header file
#include "cv.h"
#include "highgui.h"

//standard header file
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string.h>

//Global Variable
IplImage* thinimg2; //pointer for thinning
unsigned char* thindata; //data pointer for thinning
                            (skeletonization)

int width3 = thinimg2->width;
int height3 = thinimg2->height;
int channel3 = thinimg2->nChannels;
int step3 = thinimg2->widthStep;
int totalwidth3 = width3*channel3;


thindata = reinterpret_cast<unsigned char*>(thinimg2->imageData);
thindata+=step3;

    for(int ee=1; ee<height3-1; ee++)
    {
        for(int qq=channel3; qq<totalwidth3-channel3; qq+=channel3)
        {

            int neighbor = 0;
            int totalnum = 0;


            if(thindata[qq]==255)
            {
                thindata-=step3;
                //if(thindata[qq-1]==255)neighbor++;
                    if(thindata[qq]==255)neighbor++;
                        //if(thindata[qq+1]==255)neighbor++;
                            //totalnum=neighbor;

                thindata+=step3;
                if(thindata[qq-1]==255)neighbor++;
                    //if(thindata[qq]==255)neighbor++;
                        if(thindata[qq+1]==255)neighbor++;
                        //totalnum+=neighbor;

                thindata+=step3;
                //if(thindata[qq-1]==255)neighbor++;
                    if(thindata[qq]==255)neighbor++;
                        //if(thindata[qq+1]==255)neighbor++;
                            //totalnum+=neighbor;

                thindata-=step3;

                totalnum+=neighbor;

            }
                if((totalnum>=2)&&(totalnum<=6))
                {
                    //thindata[qq]=0;
                    //MessageBox("success","success",MB_OK | MB_ICONINFORMATION);
                    if(thindata[qq]==255)
                    {
                        neighbor++;
                    }

                        thindata-=step3;
                        if(thindata[qq]==0)

                        thindata+=step3;
                        if(thindata[qq+1]==0)

                        thindata+=step3;
                        if(thindata[qq]==0)

                        thindata-=step3;
                        if(thindata[qq-1]==0)
                            if(thindata[qq+1]==0)

                        thindata+=step3;
                        if(thindata[qq]==0)

                        thindata-=step3;

                        thindata[qq]=0;
                }

        }

        thindata+=step3;
    }

    cvvShowImage("Image Processing",thinimg2);
    cvReleaseImage(&thinimg2);


thanks a lot....hear from u soon.......

regards,
ck


__________________
ck.
Reply With Quote