LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

imaq MedianFilter

Hello,

 

I want to do a median filter on a picture with Imaq. To do that, I tried this code, but it doesn't work !

 

<code>

Imagesrc=imaqCreateImage (IMAQ_IMAGE_I16, 1);  
ImageDest=imaqCreateImage (IMAQ_IMAGE_I16, 1);  


Sucess = imaqSetImageSize (ImageSrc, MAX_X, MAX_Y);
Sucess = imaqSetImageSize (ImageDest, MAX_X, MAX_Y);

 

imaqGetImageInfo (ImageSrc, &infoImageSrc);
infoImageSrc.pixelsPerLine = MAX_X/2;

 

for (i=0;i<MAX_Y;i++)
     for (j=0;j<MAX_X;j++)   {
      pixel_address = (short *)infoImageSrc.imageStart + i * infoImageSrc.pixelsPerLine + j;
      *pixel_address = (short)RougeBrut[i][j];
     /* p.x = j;
      p.y = i;
      Value.grayscale = RougeBrut[i][j];
      imaqSetPixel (ImageSrc, p, Value);   */
      }

     //ImaqSucess = imaqArrayToImage (ImageSrc, ImArray, MAX_X/2, MAX_Y/2);
     //ImaqSucessText = imaqGetErrorText(ImaqSucess); 
     ImaqSucess = imaqMedianFilter (ImageDest, ImageSrc, 5, 5, NULL);
     
   
     imaqGetImageInfo(ImageDest, &infoImageDest); 
     //infoImageDest.pixelsPerLine = MAX_X/2;      
   
    for (i=0;i<MAX_Y/2;i++)
     for (j=0;j<MAX_X/2;j++)   {
      pixel_address = ((short *)(infoImageDest.imageStart) + (i * infoImageDest.pixelsPerLine + j));
      RougeBrut[i][j]= *pixel_address;
     /* p.x = j;
      p.y = i;
      imaqGetPixel (ImageDest, p, &Value);
      RougeBrut[i][j]=Value.grayscale;*/
      } 

</code>

0 Kudos
Message 1 of 4
(3,217 Views)

Hi,

 

Is it possible for you to send all your project / code in order for me to help you better ?

 

Regards,

0 Kudos
Message 2 of 4
(3,197 Views)

no wonder this does not work: it is a big mess !

- remove unused code

- use curly braces to clearly delimit your blocks (the for in the Y direction...)

- USE A CORRECT INDENTATION OF YOUR CODE !

- do not write test values inside structure which are not supposed to store them (infoImageSrc.pixelsPerLine = MAX_X/2;)

- try your code in the debugger and enable the "break on library error" options in the debug menu.

 

with such a presentation, i first thought that imaqMedianFilter() was called for each row of the image... also it seems you want to test with half an image, but your use of "/ 2"is not consistent: for the source image you are using half the rows at full width, for the dest image you are using half the rows at half width.

 

now, the documentation for imaqMedianFilter() states that "The border [of the source image] must be at least half as large as the larger of the neighborhood dimensions." your border is 1 pixel wide (see your call to imaqCreateImage()), and your filter is 5 pixels wide (see your call to imaqMedianFilter()): 5/2 = 2.5, so you should try with a 3 pixels wide border.

 

0 Kudos
Message 3 of 4
(3,171 Views)

Hello,

 

Sorry, it was a draft, I sent this message by mistake.. I resolved my problem. Thank you.

0 Kudos
Message 4 of 4
(3,159 Views)