Re: dilation



Hi back,

When you say it doesn't work, what does that mean? What does the
output look like?

You do things differently than I do, but that's just a personal thing.

inputdata is created and then never used.

You desparately need comments.

But, the thing I found that is probably giving you the bad results is
in the inner loop in the final loops: you are adding the foreground
pixel to the current pixel for each foreground pixel in the kernel.
You likely wanted to just set the pixel to the foreground and the break
out of that inner loop.

If the above doesn't do it for you, describe the output and I'll have
another look.

Cheers,

duane

h4mm3r` wrote:
Hi there,
i'm new to this group n i hope not to be out of topic.
I'm trying to create a dilate() funcion by which i can dilate my
inputimage (m_inputImage). I check all background points of my input
image, if one of them is a foreground point's neighboor (by chessboard
distance), then i add it (or them) to the object.

This is my code, but it doesn't work:


static const unsigned char foreground = 0;
static const unsigned char background = 255;

unsigned char * neighD8(IplImage *img, int r, int c) {
unsigned char *n = (unsigned char *)malloc((sizeof(unsigned char))*8);

int k=0;
for(int i = r-1; i<=r+1; i++)
for(int j = c-1; j<=c+1; j++) {
if ((i!=r)&&(j!=c)) {
n[k]=img->imageData[(i*img->widthStep)+j];
k++;
}
}
return n;
}



void dilation(void) {
int k = 1;
int *kernel = new int[(2*k+1)*(2*k+1)];

if(m_inputImage->nChannels!=1) {
AfxMessageBox("immagine RGB!");
return;
}

CvSize size;
size.height = m_inputImage->height-2*k;
size.width = m_inputImage->width-2*k;
m_outputImage = cvCreateImage(size,IPL_DEPTH_8U,1);

unsigned char* inputdata=((unsigned char*)(m_inputImage->imageData));

for(int i = 0; i < 2*k+1; i++) {
for(int j = 0; j < 2*k+1; j++) {
kernel[i*(2*k+1)+j] = (int)1;
}
}

IplImage* tempimg = autothresholding(m_inputImage);

cvNamedWindow("test", 0);
cvResizeWindow("test",tempimg->width,tempimg->height);
cvShowImage("test", tempimg);

int temp;
for(int r = 0; r < size.height; r++) {
for(int c = 0; c < size.width; c++) {
m_outputImage->imageData[(r*m_outputImage->widthStep)+c] =
tempimg->imageData[(r*tempimg->widthStep)+c];
}
}

for(int r=k; r < tempimg->height-k; r++) {
for(int c = k; c < tempimg->width-k; c++) {

if(tempimg->imageData[r*tempimg->widthStep+c] ==
background) {
unsigned char *vicinato = neighD8(tempimg,r,c);
for(int k = 0 ; k < 8; k++) {
if (vicinato[k] == foreground) {

m_outputImage->imageData[(r*m_outputImage->widthStep)+c]+=foreground;
}
}
}
}
}
}

.



Relevant Pages

  • Re: dilation
    ... one pixel off, and I had array index out of bound errors). ... int foreground = 255; ... //create binary image from the input image ... //foreground, i set it to foreground value and exit for cycle. ...
    (sci.image.processing)
  • Re: dilation
    ... It looks exact the same of the input image (tempimg) ... pixel to the current pixel for each foreground pixel in the kernel. ... int h,w; ...
    (sci.image.processing)
  • Re: UpdateLayeredWindow and alpha values
    ... *IF* you are replacing foreground with your pixel values. ... UpdateLayeredWindow uses your pixels to replace the entire term, ... If your source bitmap may or may not have an alpha channel, ...
    (microsoft.public.win32.programmer.gdi)
  • Re: colors in [pd]curses - unix vs windows
    ... letting my macros wrap, since they're just over my line length): ... int fg, bg; ... background colors separate. ... just the foreground or just the background, ...
    (rec.games.roguelike.development)