Re: dilation



vonschwartzwalder wrote:
Hi back,


Hi,
first of all thanks for having answered to my post. I just wanted to
say that i cut comments off 'cause they were in italian and i hadn't
time to comment it in english.

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

It looks exact the same of the input image (tempimg)


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

inputdata is created and then never used.
Ya i know, i've to refactor the code :(


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.


I fixed some points but it still doesn't work as it should

----

void CElabImageDlg::dilation(void) {
//kernel dimension 3x3
int k = 1;
int *kernel = new int[(2*k+1)*(2*k+1)];

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

//output image dimensions set to: (h-2k)x(w-2k)
CvSize size;
int h,w;
h = m_inputImage->height;
w = m_inputImage->width;
size.height = h-2*k;
size.width = w-2*k;
m_outputImage = cvCreateImage(size,IPL_DEPTH_8U,1);

/*
1 1 1
kernel = [ 1 1 1 ]
1 1 1

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

//create binary image from the input image (m_inputImage)
IplImage* tempimg = autothresholding(m_inputImage);

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

int temp;

//it copies the input image's binarization to the output image
//now all pixels values 1s or 0s
for(int r = k; r < size.height; r++) {
for(int c = k; c < size.width; c++) {
m_outputImage->imageData[(r*m_outputImage->widthStep)+c] =
tempimg->imageData[((r+k)*tempimg->widthStep)+(c+k)];
}
}

//it cycles on height n width of tempimg
for(int r=k; r < tempimg->height-k; r++) {
for(int c = k; c < tempimg->width-k; c++) {

//if the (r,c) pixel belongs to the background, then i'm gonna
search
//for its 8 connected pixel. If one of these pixel belongs to the
//foreground, i set it to foreground value and exit for cycle.
if(tempimg->imageData[r*tempimg->widthStep+c] ==
background) {
unsigned char *vicinato = neighD8(tempimg,r,c);
for(int z = 0 ; z < 8; z++) {
if (vicinato[z] == foreground) {
m_outputImage->imageData[((r-k)*m_outputImage->widthStep)+(c-k)]=foreground;
break;
}
}
}
}
}

}

---

Thanks

.



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
    ... pixel to the current pixel for each foreground pixel in the kernel. ... static const unsigned char background = 255; ... int k = 1; ...
    (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)
  • Malloc code
    ... set up some data in a strucuture called GMM. ... struct GMM{ ... will be displayed starting at pixel. ... int SETWINEXTHORZ_MSB, ...
    (microsoft.public.vc.language)
  • Re: Back to getting pixel RGBColor values from a pixmap
    ... >> RGBColor getpixel(GWorldPtr Source, int H, int V) ... > you can have a 16x16 pixel GWorld with topleft at. ...
    (comp.sys.mac.programmer.help)