<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<META content="MSHTML 6.00.5730.13" name=GENERATOR></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma" text=#000000 bgColor=#ffffff>Markus you are right, the error is introduced because of imagecast which is actually implemented in terms of static_cast, this causes numbers like 8.9999 to be rounded down to 8. Instead what I should actually have is a filter that first rounds the data to the nearest integer before casting it to the data type I need.<BR><BR>>>> Markus Neuner <neuner.markus@gmx.net> 19/08/2010 18:45 >>><BR>
<DIV style="COLOR: #000000">Looks like a casting error because of your data type "UnsignedShort".<BR><BR><<< snip >>><BR>vtkImageCast cast<BR>cast SetInputConnection [real GetOutputPort]<BR>cast SetOutputScalarTypeToUnsignedShort<BR>cast Update<BR><<< snap >><BR><BR>What is the result when you change the type to float/double?<BR><BR><BR>On 19.08.2010 17:54, John Fraser wrote:
<BLOCKQUOTE cite=mid:20100819T165459Z_B96900170000@icr.ac.uk type="cite">
<META content="MSHTML 6.00.5730.13" name=GENERATOR>
<DIV>Hello,</DIV>
<DIV> </DIV>
<DIV>I'm trying to implement convolutional coding using FFT (based upon TestFFTCorrelation.tcl). The problem is I'm getting off by 1 "errors" in the results. I'm not sure if this is expected or not, I thought that VTK FFT based convolution should return exactly the same results as Matlab. I've tried padding the image with zeros as well but I can't get the results to be the same. Any ideas why they are different?</DIV>
<DIV> </DIV>
<DIV>To test this my kernel is 3 X 3 filled with 1s and my image is 10 X 10 filled with 1s. The result from VTK is:</DIV>
<DIV> </DIV>
<DIV> 8 9 8 8 8 8 9 8 8 8<BR> 8 9 8 8 8 8 9 8 8 8<BR> 9 9 9 8 8 9 9 9 8 8<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 8 8 9 9 9 8 8<BR> 8 9 8 8 8 8 9 8 8 8<BR> 8 9 8 8 8 8 9 8 8 8<BR> 9 9 9 8 8 9 9 9 8 8<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 8 8 9 9 9 8 8</DIV>
<DIV> </DIV>
<DIV>whereas Matlab produces all 9s using ifft2( fft2( d ).*fft2( k ) )</DIV>
<DIV> </DIV>
<DIV> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9<BR> 9 9 9 9 9 9 9 9 9 9</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Code (using VTK TCL binary, based upon TestFFTCorrelation.tcl):</DIV>
<DIV><BR>set dims 2<BR>set imgdim 9<BR>set kerdim 2</DIV>
<DIV> </DIV>
<DIV>vtkImageReader image1</DIV>
<DIV># sample image is all 1s 10 X 10 = 100 bytes<BR>image1 SetFileName "SampleImg.bin"<BR>image1 SetHeaderSize 0<BR>image1 SetDataByteOrderToLittleEndian<BR>image1 SetFileDimensionality $dims<BR>image1 SetDataOrigin 0 0 0<BR>image1 SetDataSpacing 1 1 1<BR>image1 SetNumberOfScalarComponents 1<BR>image1 SetDataExtent 0 $imgdim 0 $imgdim 0 0<BR>image1 SetDataScalarTypeToUnsignedChar</DIV>
<DIV> </DIV>
<DIV>vtkImageReader kernel<BR># kernel image is all 1s 3 X 3 = 9 bytes</DIV>
<DIV>kernel SetFileName "Kernel.bin"<BR>kernel SetHeaderSize 0<BR>kernel SetDataByteOrderToLittleEndian<BR>kernel SetFileDimensionality $dims<BR>kernel SetDataOrigin 0 0 0<BR>kernel SetDataSpacing 1 1 1<BR>kernel SetNumberOfScalarComponents 1<BR>kernel SetDataExtent 0 $kerdim 0 $kerdim 0 0<BR>kernel SetDataScalarTypeToUnsignedChar</DIV>
<DIV> </DIV>
<DIV>vtkImageFFT fft1<BR>fft1 SetDimensionality $dims<BR>fft1 SetInputConnection [image1 GetOutputPort]</DIV>
<DIV> </DIV>
<DIV>vtkImageConstantPad pad2<BR>pad2 SetInputConnection [kernel GetOutputPort]<BR>pad2 SetOutputWholeExtent 0 $imgdim 0 $imgdim 0 0</DIV>
<DIV> </DIV>
<DIV>vtkImageFFT fft2<BR>fft2 SetDimensionality $dims<BR>fft2 SetInputConnection [pad2 GetOutputPort]</DIV>
<DIV> </DIV>
<DIV>vtkImageMathematics mult<BR>mult SetOperationToComplexMultiply<BR>mult SetInput1 [fft1 GetOutput]<BR>mult SetInput2 [fft2 GetOutput]</DIV>
<DIV> </DIV>
<DIV>vtkImageRFFT rfft<BR>rfft SetDimensionality $dims<BR>rfft SetInputConnection [mult GetOutputPort]</DIV>
<DIV> </DIV>
<DIV>vtkImageExtractComponents real<BR>real SetInputConnection [rfft GetOutputPort]<BR>real SetComponents 0</DIV>
<DIV> </DIV>
<DIV>vtkImageCast cast<BR>cast SetInputConnection [real GetOutputPort]<BR>cast SetOutputScalarTypeToUnsignedShort<BR>cast Update</DIV>
<DIV> </DIV>
<DIV>vtkImageWriter writer<BR>writer SetInputConnection [cast GetOutputPort]<BR>writer SetFileName "VTK.img"<BR>writer SetFileDimensionality $dims<BR>writer Write</DIV>
<DIV> </DIV>
<DIV>exit<BR></DIV><PRE wrap=""><FIELDSET class=mimeAttachmentHeader></FIELDSET>
_______________________________________________
Powered by <A class=moz-txt-link-abbreviated href="http://www.kitware.com">www.kitware.com</A>
Visit other Kitware open-source projects at <A class=moz-txt-link-freetext href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</A>
Please keep messages on-topic and check the VTK FAQ at: <A class=moz-txt-link-freetext href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</A>
Follow this link to subscribe/unsubscribe:
<A class=moz-txt-link-freetext href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</A>
</PRE></BLOCKQUOTE></DIV></BODY></HTML>