<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello RTK-users,</p>
    <p>as a newbie, I am not yet familiar with the way how to correctly use RTK, so my apologies if I am asking something dumb.</p>
    <p>My question is (short version):</p>
    <p>Is there a way to use rtk::ProjectionsReader with images that have files and columns transposed with respect to the convention (wrt the rotation axis)? And if not, would it be possible to add such a feature in the future?</p>
    <p>
</p>
    <p>The long story:
</p>
    <p><style type="text/css">IFp, li { white-space: pre-wrap; }</style></p>
    <p>Currently, I am trying to migrate a script I wrote in MATLAB, which correctly performs a 3D reconstruction based on 360 projections (2D). Thus, I am sure that my geometry parameters and input data are correct. I open them exaclty in the same format both in MATLAB and in RTK (as uint16).
</p>
    <p>The MATLAB script does something like this (The flip below is because projections go from 0, -1, -2, ... degrees):</p>
    <p>
ctWidth = 768
ctHeight = 486
pitch = 0.075*4
allProjections = zeros(ctWidth,ctHeight,ctProjections,'uint16');
for proj = 1:ctProjections
    allProjections(:,:,proj) = fread(fopen(projfile(proj),'rb','l'),[ctWidth,ctHeight],'uint16');
end
Di = 90; % isocenter to detector distance mm
Ds = 151; % isocenter to source distance mm
offset = 1.6; % mm
for i = 1:ctHeight
    Ifan(i) = ifanbeam( ...
    log(16383./flip(single(squeeze(allProjections(round(offset*2/pitch):end,i,:))),2)), ...
    Ds/pitch, ...
        'FanSensorSpacing',Ds/(Di+Ds), ...
        'FanSensorGeometry','line', ...
        'Filter', 'Hann', ...
        'OutputSize', 700);
end
</p>
    <p>And after saving Ifan, it correctly generates a 3D image that I can open with Slicer3D. ( A cylinder with some wires).

<style type="text/css">.rtcContent { padding: 30px; }.lineNode {font-size: 10pt; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-style: normal; font-weight: normal; }</style></p>
    <p><img src="cid:part1.ZYKUfj0M.rKxmWTbf@uv.es" alt="" class="" width="328" height="175"></p>
    <p>Now, if I try to do the same thing with RTK in C++, I cannot seem to find the proper settings to do the exact same reconstruction.
First I try to define the geometry and input format:
</p>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">using</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">GeometryType</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">rtk</span>::<span style=" color:#800080;">ThreeDCircularProjectionGeometry</span>;</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">GeometryType</span>::<span style=" color:#800080;">Pointer</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">geometry</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">GeometryType</span>::<span style=" color:#00677c;">New</span>();</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">for</span><span style=" color:#c0c0c0;"> </span>(<span style=" color:#800080;">size_t</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">i</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span>;<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">i</span><span style=" color:#c0c0c0;"> </span><<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">360</span>;<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">i</span>++)<span style=" color:#c0c0c0;"> </span>{</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">float</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">angle</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>-<span style=" color:#092e64;">i</span>;</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">float</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">sid</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">151</span>;</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">float</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">sdd</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">90+151</span>;</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">        </span><span style=" color:#092e64;">geometry</span>-><span style=" color:#00677c;">AddProjection</span>(<span style=" color:#092e64;">sid</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">sdd</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">angle</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">1.6</span>);</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span>}

<span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">ImageIOType</span>::<span style=" color:#800080;">Pointer</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">io</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">ImageIOType</span>::<span style=" color:#00677c;">New</span>();
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">io</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetDimensions</span>(<span style=" color:#000080;">0</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">ctWidth</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">io</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetDimensions</span>(<span style=" color:#000080;">1</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">ctHeight</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">io</span><span style=" color:#00677c;">-></span><span style=" color:#00677c;">SetByteOrderToLittleEndian</span>();
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">io</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetOrigin</span>(<span style=" color:#000080;">0</span>,<span style=" color:#c0c0c0;"> </span>-<span style=" color:#092e64;">detPitchU</span><span style=" color:#c0c0c0;"> </span>*<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">detSizeU</span><span style=" color:#c0c0c0;"> </span>/<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">2</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">io</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetOrigin</span>(<span style=" color:#000080;">1</span>,<span style=" color:#c0c0c0;"> </span>-<span style=" color:#092e64;">detPitchV</span><span style=" color:#c0c0c0;"> </span>*<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">detSizeV</span><span style=" color:#c0c0c0;"> </span>/<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">2</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">io</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetSpacing</span>(<span style=" color:#000080;">0</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">detPitchU</span><span style=" color:#c0c0c0;"> </span>*<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">binningU</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">io</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetSpacing</span>(<span style=" color:#000080;">1</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">detPitchV</span><span style=" color:#c0c0c0;"> </span>*<span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">binningV</span>);


<span style=" color:#c0c0c0;">    </span><span style=" color:#808000;">using</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">NameGeneratorType</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">itk</span>::<span style=" color:#800080;">NumericSeriesFileNames</span>;
<span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">NameGeneratorType</span>::<span style=" color:#800080;">Pointer</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">nameGenerator</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">NameGeneratorType</span>::<span style=" color:#00677c;">New</span>();
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">nameGenerator</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetSeriesFormat</span>(<span style=" color:#092e64;">subfolder</span><span style=" color:#c0c0c0;"> </span><span style=" color:#00677c;">+</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"/%d.ct"</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">nameGenerator</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetStartIndex</span>(<span style=" color:#000080;">0</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">nameGenerator</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetEndIndex</span>(<span style=" color:#000080;">359</span>);
<span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">nameGenerator</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetIncrementIndex</span>(<span style=" color:#000080;">1</span>);
</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#808000;">    
    using</span><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">ReaderType</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">rtk</span>::<span style=" color:#800080;">ProjectionsReader</span><<span style=" color:#800080;">OutputImageType</span>>;</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#800080;">ReaderType</span>::<span style=" color:#800080;">Pointer</span><span style=" color:#c0c0c0;"> </span><span style=" color:#092e64;">reader</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">ReaderType</span>::<span style=" color:#00677c;">New</span>();</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">reader</span><span style=" color:#00677c;">-></span><span style=" color:#00677c;">SetFileNames</span>(<span style=" color:#092e64;">nameGenerator</span><span style=" color:#00677c;">-></span><span style=" color:#00677c;">GetFileNames</span>());</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">reader</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetImageIO</span>(<span style=" font-style:italic; color:#092e64;">io</span>);</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">reader</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">SetI0</span>(<span style=" color:#000080;">16383</span>);</pre>
    <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" color:#c0c0c0;">    </span><span style=" color:#092e64;">reader</span><span style=" color:#00677c;">-></span><span style=" font-style:italic; color:#00677c;">Update</span>();</pre>
    <p><style type="text/css">p, li { white-space: pre-wrap; }</style></p>
    <p>After reconstructing, it looks then transposed with respect to the MATLAB version. The circular section is on the right, and the vertical cylinder on the left. (Sorry about it not being centered, that's my bad.). (Changing 'nColumns' with 'nRows' of course does not solve the issue, as this would lead to wrong 2D images being imported.)</p>
    <p><img src="cid:part2.O0vmbprS.NZSeu2B0@uv.es" alt="" class="" width="332" height="173"></p>
    <p>
</p>
    <p>So the question would be if there is a way to solve this without having to mess around with my data. Maybe there is a 'transpose flag' that I have overlooked when calling rtk-projectionsreader?

If you prefer, I can share with you the full script and input data via my Cloud-Drive.</p>
    <p>
</p>
    <p>Thanks in advance for the help! Have a nice weekend.</p>
    <p>Fernando.</p>
  </body>
</html>