Skip to content

Commit

Permalink
Swizzle dims 3 and 4 for 2dseq without reco files
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Mar 7, 2017
1 parent e0ccc75 commit c14f1ed
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 44 deletions.
45 changes: 45 additions & 0 deletions Bru2.app/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>Bru2</string>
<key>CFBundleName</key>
<string>Bru2</string>
<key>CFBundleIdentifier</key>
<string>com.company.Bru2</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>Bru2</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
</array>
<key>CFBundleTypeOSTypes</key>
<array>
<string>fold</string>
<string>disk</string>
<string>****</string>
</array>
</dict>
</array>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
1 change: 1 addition & 0 deletions Bru2.app/Contents/MacOS/Bru2
1 change: 1 addition & 0 deletions Bru2.app/Contents/PkgInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APPL????
76 changes: 38 additions & 38 deletions Bru2Nii.lps
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Filename Value="Bru2Nii.lpr"/>
<IsPartOfProject Value="True"/>
<CursorPos X="3" Y="16"/>
<UsageCount Value="128"/>
<UsageCount Value="130"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit0>
Expand All @@ -20,7 +20,7 @@
<EditorIndex Value="1"/>
<TopLine Value="74"/>
<CursorPos X="15" Y="79"/>
<UsageCount Value="128"/>
<UsageCount Value="130"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
Expand All @@ -29,7 +29,7 @@
<IsPartOfProject Value="True"/>
<TopLine Value="88"/>
<CursorPos Y="108"/>
<UsageCount Value="127"/>
<UsageCount Value="129"/>
</Unit2>
<Unit3>
<Filename Value="convert.pas"/>
Expand All @@ -41,9 +41,9 @@
<Filename Value="common.inc"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<TopLine Value="881"/>
<CursorPos X="49" Y="907"/>
<UsageCount Value="42"/>
<TopLine Value="826"/>
<CursorPos X="30" Y="831"/>
<UsageCount Value="43"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
Expand All @@ -52,130 +52,130 @@
<EditorIndex Value="3"/>
<TopLine Value="176"/>
<CursorPos X="3" Y="32"/>
<UsageCount Value="33"/>
<UsageCount Value="34"/>
<Loaded Value="True"/>
</Unit5>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="common.inc"/>
<Caret Line="896" Column="19" TopLine="878"/>
<Caret Line="799" Column="9" TopLine="784"/>
</Position1>
<Position2>
<Filename Value="common.inc"/>
<Caret Line="828" Column="20" TopLine="822"/>
<Caret Line="807" Column="7" TopLine="785"/>
</Position2>
<Position3>
<Filename Value="common.inc"/>
<Caret Line="829" Column="20" TopLine="822"/>
<Caret Line="351" Column="41" TopLine="339"/>
</Position3>
<Position4>
<Filename Value="common.inc"/>
<Caret Line="830" Column="20" TopLine="822"/>
<Caret Line="376" Column="22" TopLine="354"/>
</Position4>
<Position5>
<Filename Value="common.inc"/>
<Caret Line="833" Column="13" TopLine="822"/>
<Caret Line="377" Column="29" TopLine="355"/>
</Position5>
<Position6>
<Filename Value="common.inc"/>
<Caret Line="242" Column="20" TopLine="237"/>
<Caret Line="807" Column="7" TopLine="785"/>
</Position6>
<Position7>
<Filename Value="common.inc"/>
<Caret Line="828" Column="20" TopLine="812"/>
<Caret Line="340" Column="43" TopLine="339"/>
</Position7>
<Position8>
<Filename Value="common.inc"/>
<Caret Line="830" Column="20" TopLine="814"/>
<Caret Line="800" TopLine="786"/>
</Position8>
<Position9>
<Filename Value="common.inc"/>
<Caret Line="831" Column="20" TopLine="815"/>
<Caret Line="810" Column="10" TopLine="790"/>
</Position9>
<Position10>
<Filename Value="common.inc"/>
<Caret Line="834" Column="13" TopLine="818"/>
<Caret Line="834" Column="5" TopLine="825"/>
</Position10>
<Position11>
<Filename Value="common.inc"/>
<Caret Line="278" Column="21" TopLine="270"/>
<Caret Line="805" Column="22" TopLine="796"/>
</Position11>
<Position12>
<Filename Value="common.inc"/>
<Caret Line="832" Column="74" TopLine="825"/>
<Caret Line="794" Column="35" TopLine="792"/>
</Position12>
<Position13>
<Filename Value="common.inc"/>
<Caret Line="834" Column="13" TopLine="825"/>
<Caret Line="797" Column="19" TopLine="793"/>
</Position13>
<Position14>
<Filename Value="common.inc"/>
<Caret Line="284" Column="9" TopLine="265"/>
<Caret Line="808" Column="20" TopLine="799"/>
</Position14>
<Position15>
<Filename Value="common.inc"/>
<Caret Line="280" Column="48" TopLine="269"/>
<Caret Line="838" Column="3" TopLine="832"/>
</Position15>
<Position16>
<Filename Value="common.inc"/>
<Caret Line="830" Column="27" TopLine="826"/>
<Caret Line="803" Column="12" TopLine="800"/>
</Position16>
<Position17>
<Filename Value="common.inc"/>
<Caret Line="869" Column="68" TopLine="862"/>
<Caret Line="932" Column="26" TopLine="917"/>
</Position17>
<Position18>
<Filename Value="common.inc"/>
<Caret Line="905" Column="16" TopLine="888"/>
<Caret Line="283" Column="45" TopLine="275"/>
</Position18>
<Position19>
<Filename Value="common.inc"/>
<Caret Line="901" Column="48" TopLine="889"/>
<Caret Line="288" Column="51" TopLine="275"/>
</Position19>
<Position20>
<Filename Value="common.inc"/>
<Caret Line="883" Column="84" TopLine="858"/>
<Caret Line="932" Column="26" TopLine="917"/>
</Position20>
<Position21>
<Filename Value="common.inc"/>
<Caret Line="728" Column="66" TopLine="720"/>
<Caret Line="279" Column="10" TopLine="275"/>
</Position21>
<Position22>
<Filename Value="common.inc"/>
<Caret Line="831" Column="33" TopLine="822"/>
<Caret Line="5" Column="93"/>
</Position22>
<Position23>
<Filename Value="common.inc"/>
<Caret Line="826" Column="20" TopLine="817"/>
<Caret Line="424" Column="60" TopLine="409"/>
</Position23>
<Position24>
<Filename Value="common.inc"/>
<Caret Line="873" Column="122" TopLine="860"/>
<Caret Line="28" Column="54" TopLine="16"/>
</Position24>
<Position25>
<Filename Value="common.inc"/>
<Caret Line="846" Column="19" TopLine="838"/>
<Caret Line="936" Column="5" TopLine="919"/>
</Position25>
<Position26>
<Filename Value="common.inc"/>
<Caret Line="808" Column="19" TopLine="790"/>
<Caret Line="739" Column="20" TopLine="736"/>
</Position26>
<Position27>
<Filename Value="common.inc"/>
<Caret Line="858" Column="19" TopLine="837"/>
<Caret Line="810" Column="37" TopLine="802"/>
</Position27>
<Position28>
<Filename Value="common.inc"/>
<Caret Line="688" Column="15" TopLine="672"/>
<Caret Line="26" Column="71" TopLine="20"/>
</Position28>
<Position29>
<Filename Value="main.pas"/>
<Caret Line="79" Column="57" TopLine="62"/>
<Filename Value="common.inc"/>
<Caret Line="877" Column="7" TopLine="865"/>
</Position29>
<Position30>
<Filename Value="common.inc"/>
<Caret Line="896" Column="37" TopLine="878"/>
<Caret Line="795" Column="20" TopLine="782"/>
</Position30>
</JumpHistory>
</ProjectSession>
Expand Down
40 changes: 34 additions & 6 deletions common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type
end;
TMat = array[1..4, 1..4] of single;
TBrukerHdr = Record
RECO_byte_order_little, RECO_transposition_varies: boolean;
RECO_byte_order_little, RECO_transposition_varies, has_d3proc_file: boolean;
RECO_transposition, RECO_wordtype_bits, ACQ_ns_list_size, ACQ_nr_completed, ACQ_NR, ACQ_NI, ACQ_NSLICES, METHOD_PVM_ObjOrderScheme: integer;
RECO_map_offset, RECO_map_slope, ACQ_RG, ACQ_slice_thick,ACQ_read_offset, ACQ_phase1_offset, METHOD_slice_offset, METHOD_slice_distance: single;
METHOD_PVM_SpatResol,RECO_offset, RECO_size, RECO_fov, ACQ_grad_matrix, ACQ_slice_sepn, ACQ_repetition_time : TVec;
Expand Down Expand Up @@ -787,13 +787,39 @@ begin
wp^[i] := swap(wp^[i]);
end;

procedure CpyImg (lRawFName, lNiiFName: string; ImgBytes: integer; BrHdr: TBrukerHdr);
procedure SwapDimsZT(p: Pointer; ImgBytes: integer; lNiHdr: TNiHdr);
//swizzle 3rd and 4th dimensions
type
ByteRA0 = array [0..0] of byte;
Bytep0 = ^ByteRA0;
var
xyBytes, xyzBytes, z, t, posIn, posOut: integer;
pIn, pOut: Bytep0;
begin
xyBytes := lNiHdr.dim[1]*lNiHdr.dim[2]*(lNiHdr.bitpix div 8);
if (lNiHdr.dim[3] < 2) or (lNiHdr.dim[4] < 2) or ((xyBytes*lNiHdr.dim[3]*lNiHdr.dim[4]) <> ImgBytes) then exit;
xyzBytes := xyBytes * lNiHdr.dim[3];
getmem(pIn, ImgBytes);
Move(p^,pIn^,ImgBytes);//src, dest, bytes
pOut := Bytep0(p);
posIn := 0;
for z := 1 to lNiHdr.dim[3] do begin
for t := 1 to lNiHdr.dim[4] do begin
posOut := ((t-1)*xyzBytes) + ((z-1) * xyBytes);
Move(pIn^[posIn],pOut^[posOut], xyBytes);//src, dest, bytes
inc(posIn, xyBytes);
end;
end;
freemem(pIn);
end;

procedure CpyImg (lRawFName, lNiiFName: string; ImgBytes: integer; BrHdr: TBrukerHdr; lNiHdr: TNiHdr);
//copy image data from Bruker 2dseq file to NIfTI .nii file: forces native byte order
var
lOutF,lInF: File of byte;
p: Pointer;
begin
getmem(p, ImgBytes);
getmem(p, ImgBytes);
AssignFile(lInF, lRawFName);
Reset(lInF);
FileMode := 0; //Set file access to read only
Expand All @@ -810,6 +836,8 @@ begin
if (BrHdr.RECO_wordtype_bits = 16) then
Swap16(p, ImgBytes);
end; //swap image data to have native endian
if BrHdr.has_d3proc_file then //based on one image from Mikaël Naveau
SwapDimsZT(p, ImgBytes, lNiHdr);
AssignFile(lOutF, lNiiFName);
Reset(lOutF);
Seek(lOutF, sizeof(TNiHdr));
Expand Down Expand Up @@ -843,11 +871,11 @@ begin
if not BrReadACQP(lAcqpFName, BrHdr) then exit;
if not BrReadRECO(lRecoFName, BrHdr) then exit;
BrReadMETHOD(lMethodFName, BrHdr);
if fileexists(ExtractFilePath(lImgFName)+ 'd3proc') then begin
BrHdr.has_d3proc_file := fileexists(ExtractFilePath(lImgFName)+ 'd3proc');
if BrHdr.has_d3proc_file then begin
showmsg('Found "d3proc" file: assuming 32-bit data');
BrHdr.RECO_wordtype_bits := 32;
end;

//Label files based on EXPNO and PROCNO: ACQP is in EXPNO directory 2dSeq in PROCNO directory
if lOutFName = '' then
lOutFName := ExtractFilePath(lAcqpFName)+'X'+Extractfilename(ExtractFileDir(lAcqpFName))+'P'+ Extractfilename(ExtractFileDir(lImgFName))+'.nii'
Expand All @@ -866,7 +894,7 @@ begin
BrReport(BrHdr, lRecoFName, lOutFName, lVerbose);
BrMat (BrHdr, NiHdr, lFOVx10, lVerbose);
SaveNiHdr (lOutFName, NiHdr);
CpyImg (lImgFName, lOutFName, ImgBytes, BrHdr);
CpyImg (lImgFName, lOutFName, ImgBytes, BrHdr, NiHdr);
end;

procedure Find2Dseq(Dir, OutFName: string; FOVx10, lVerbose, OnlyConvert3D, AppendProtocolName: boolean; var nOK: integer);
Expand Down
Binary file modified compiled/osx_MacOS.zip
Binary file not shown.

0 comments on commit c14f1ed

Please sign in to comment.