Re: dilation
- From: "vonschwartzwalder" <vonschwartzwalder@xxxxxxx>
- Date: 11 Jul 2006 13:54:47 -0700
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;
}
}
}
}
}
}
.
- Follow-Ups:
- Re: dilation
- From: h4mm3r`
- Re: dilation
- References:
- dilation
- From: h4mm3r`
- dilation
- Prev by Date: Re: imaing inudstry in the US
- Next by Date: Re: MRI registered on X-ray
- Previous by thread: dilation
- Next by thread: Re: dilation
- Index(es):
Relevant Pages
|