From 1cc476d796e4fe16192e3c612839f3da296609bb Mon Sep 17 00:00:00 2001 From: Robert Smith Date: Thu, 15 Feb 2024 17:31:56 +1100 Subject: [PATCH] PNG handling fixes - Fix erroneous modification of strides upon header concatenation; this replicates the fix included in 41c02e9 as part of #2806, but is necessary for the suite of fixes here to work. Note that this affects mrcat in addition to multi-image format handling. - Fix setting of strides upon PNG read. - Expand testing of PNG handling. Evaluation of read and write functionality is performed separately, with the reference data fully visible and verifiable within the test data repository. Some previous tests bundled read and write testing together, which obscured the erroneous intermediate interpretation. --- core/formats/png.cpp | 8 ++++---- core/header.cpp | 5 +++-- testing/binaries/data | 2 +- testing/binaries/tests/mrconvert | 19 ++++++++++++------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/core/formats/png.cpp b/core/formats/png.cpp index 54e74c42e7..7aa972e96d 100644 --- a/core/formats/png.cpp +++ b/core/formats/png.cpp @@ -70,16 +70,16 @@ namespace MR } H.size(0) = png.get_width(); - H.stride(0) = -3; + H.stride(0) = -2; H.size(1) = png.get_height(); - H.stride(1) = -4; + H.stride(1) = -3; H.size(2) = 1; - H.stride(2) = 1; + H.stride(2) = 4; if (H.ndim() == 4) - H.stride(3) = 2; + H.stride(3) = 1; H.spacing (0) = H.spacing (1) = H.spacing (2) = 1.0; H.transform().setIdentity(); diff --git a/core/header.cpp b/core/header.cpp index ad5b49acf8..48240f20af 100644 --- a/core/header.cpp +++ b/core/header.cpp @@ -785,12 +785,13 @@ namespace MR Header result (headers[0]); if (axis_to_concat >= result.ndim()) { + Stride::symbolise (result); result.ndim() = axis_to_concat + 1; result.size(axis_to_concat) = 1; + result.stride(axis_to_concat) = axis_to_concat+1; + Stride::actualise (result); } - result.stride (axis_to_concat) = result.ndim()+1; - for (size_t axis = 0; axis != result.ndim(); ++axis) { if (axis != axis_to_concat && result.size (axis) <= 1) { for (const auto& H : headers) { diff --git a/testing/binaries/data b/testing/binaries/data index 68869a7fe0..f65db971d0 160000 --- a/testing/binaries/data +++ b/testing/binaries/data @@ -1 +1 @@ -Subproject commit 68869a7fe0780c7b1e9577ba68466d5b407a3fe8 +Subproject commit f65db971d019675874751c2111877531e8bb5544 diff --git a/testing/binaries/tests/mrconvert b/testing/binaries/tests/mrconvert index 4b9460dcce..e012f18e92 100644 --- a/testing/binaries/tests/mrconvert +++ b/testing/binaries/tests/mrconvert @@ -8,8 +8,8 @@ mrconvert mrconvert/in.mif tmp.nii && testing_diff_image tmp.nii mrconvert/in.m mrconvert mrconvert/in.mif -datatype float32 tmp.nii.gz -force && testing_diff_image tmp.nii.gz mrconvert/in.mif mrconvert mrconvert/in.mif -strides 3,2,1 tmp.mgh && testing_diff_image tmp.mgh mrconvert/in.mif mrconvert mrconvert/in.mif -strides 1,3,2 -datatype int16 tmp.mgz && testing_diff_image tmp.mgz mrconvert/in.mif -mrconvert mrconvert/in.mif tmp-[].png && echo -e "1 0 0 0\n0 1 0 0\n0 0 1 0\n" > tmp.txt && testing_diff_image tmp-[].png $(mrcalc mrconvert/in.mif 0 -max - | mrtransform - -replace tmp.txt -) -mrconvert unit_warp.mif tmp-[].png -datatype uint8 -force && echo -e "1 0 0 0\n0 1 0 0\n0 0 1 0\n" > tmp.txt && testing_diff_image tmp-[].png $(mrcalc unit_warp.mif 0 -max -round - | mrtransform - -replace tmp.txt - | mrconvert - -vox 1,1,1 -) +rm -f tmp-*.png && mrconvert mrconvert/in.mif tmp-[].png && testing_diff_image tmp-[].png $(mrcalc mrconvert/in.mif 0 -max - | mrtransform - -replace identity.txt -) +rm -f tmp-*.png && mrconvert unit_warp.mif tmp-[].png -datatype uint8 && testing_diff_image tmp-[].png $(mrcalc unit_warp.mif 0 -max -round - | mrtransform - -replace identity.txt - | mrconvert - -vox 1,1,1 -) mrconvert dwi.mif tmp-[].mif -force && testing_diff_image dwi.mif tmp-[].mif mrconvert dwi.mif -coord 3 0:2:end tmp1.mif -force && mrconvert tmp-[0:2:66].mif tmp2.mif && testing_diff_header -keyval tmp1.mif tmp2.mif && testing_diff_image tmp1.mif tmp2.mif mrconvert mrcat/voxel[].mih - | testing_diff_header -keyval - mrcat/all_axis0.mif @@ -17,8 +17,13 @@ mrconvert mrcat/all_axis3.mif tmp-[].mif -force && testing_diff_header -keyval t mrconvert dwi.mif tmp-[]-[].mif -force && testing_diff_image dwi.mif tmp-[]-[].mif mrconvert dwi.mif -coord 3 1:2:end -axes 0:2,-1,3 - | testing_diff_image - mrconvert/dwi_select_axes.mif mrinfo template.mif.gz -transform > tmp.txt && mrconvert template.mif.gz tmp[].png -force && mrconvert tmp[].png -vox 2.5 - | mrtransform - -replace tmp.txt - | mrcalc - 255 -div - | testing_diff_image - $(mrcalc template.mif.gz 1.0 -min -) -abs 0.002 -rm -f tmpaxial*.png && mrconvert template.mif.gz -coord 2 9,19,29,39,49 tmpaxial[].png && testing_diff_image tmpaxial[].png mrconvert/axial[].png -rm -f tmpcoronal*.png && mrconvert template.mif.gz -coord 1 17,32,47,62,77 -axes 0,2,1 tmpcoronal[].png && testing_diff_image tmpcoronal[].png mrconvert/coronal[].png -rm -f tmpsagittal*.png && mrconvert template.mif.gz -coord 0 27,47,67 -axes 1,2,0 tmpsagittal[].png && testing_diff_image tmpsagittal[].png mrconvert/sagittal[].png -rm -f tmpmask*.png && mrconvert mask.mif tmpmask[].png && testing_diff_image tmpmask[].png mrconvert/mask[].png -rm -f tmptissues*.png && mrconvert dwi2fod/msmt/tissues.mif tmptissues[].png && testing_diff_image tmptissues[].png mrconvert/tissues[].png +rm -f tmpaxial*.png && mrconvert template.mif.gz -coord 2 9,19,29,39,49 tmpaxial[].png && testing_diff_image tmpaxial[].png mrconvert/pngaxial[].png +mrconvert mrconvert/pngaxial[].png - | testing_diff_image - mrconvert/pngaxial.mif.gz +rm -f tmpcoronal*.png && mrconvert template.mif.gz -coord 1 17,32,47,62,77 -axes 0,2,1 tmpcoronal[].png && testing_diff_image tmpcoronal[].png mrconvert/pngcoronal[].png +mrconvert mrconvert/pngcoronal[].png - | testing_diff_image - $(mrconvert mrconvert/pngcoronal.mif.gz -axes 0,2,1 -) +rm -f tmpsagittal*.png && mrconvert template.mif.gz -coord 0 27,47,67 -axes 1,2,0 tmpsagittal[].png && testing_diff_image tmpsagittal[].png mrconvert/pngsagittal[].png +mrconvert mrconvert/pngsagittal[].png - | testing_diff_image - $(mrconvert mrconvert/pngsagittal.mif.gz -axes 1,2,0 -) +rm -f tmpmask*.png && mrconvert mask.mif tmpmask[].png && testing_diff_image tmpmask[].png mrconvert/pngmask[].png +mrconvert mrconvert/pngmask[].png - | testing_diff_image - mrconvert/pngmask.mif.gz +rm -f tmptissues*.png && mrconvert dwi2fod/msmt/tissues.mif tmprgb[].png && testing_diff_image tmprgb[].png mrconvert/pngrgb[].png +mrconvert mrconvert/pngrgb[].png - | testing_diff_image - $(mrconvert dwi2fod/msmt/tissues.mif -vox 1,1,1 - | mrtransform - -replace identity.txt - | mrcalc - 255 -mult -round 255 -min -)