<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
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 http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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>
</body>
</html>