Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2005, 09:48 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)

//structure element for thinning
IplConvKernel* element = 0;
const int element_shape = CV_SHAPE_RECT;

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Document Image Processing (DIP) - changing image f ALcom Access 0 March 27th, 2006 06:10 AM
wat wrong of my code (image processing) ck C++ Programming 0 March 3rd, 2005 09:52 AM
image processing ck C++ Programming 0 February 27th, 2005 03:33 AM
image processing ck Visual C++ 0 February 27th, 2005 03:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.