Skip to content

Commit

Permalink
Fix tiff writing bugs (out of order tiff tags)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Sep 23, 2024
1 parent 5624924 commit c705a3b
Show file tree
Hide file tree
Showing 134 changed files with 58 additions and 52 deletions.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/Cubic m-3 (Th).tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/Cubic m-3 (Th)_FULL.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/[001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/[011]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/[111]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/ipf_test_image_0_0_1_Red.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/ipf_test_image_0_1_1_Blue.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/ipf_test_image_0_1_2_Pink.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/ipf_test_image_1_0_1_Green.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/ipf_test_image_1_0_2_Yellow.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/ipf_test_image_1_1_1_Aqua.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3 (Th)/ipf_test_image_1_1_2_Flesh.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/Cubic m-3m (Oh).tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/Cubic m-3m (Oh)_FULL.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/[001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/[011]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/[111]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/ipf_test_image_0_0_1_Red.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/ipf_test_image_0_1_1_Green.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/ipf_test_image_0_2_1_Yellow.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/ipf_test_image_1_1_1_Blue.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/ipf_test_image_1_1_2_Pink.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Cubic m-3m (Oh)/ipf_test_image_1_2_2_Aqua.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_m (C6h)/Hexagonal 6_m (C6h).tiff
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_m (C6h)/[0001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_m (C6h)/[11-20]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_m (C6h)/[2-1-10]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_mmm (D6h)/Hexagonal 6_mmm (D6h).tiff
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_mmm (D6h)/[0001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_mmm (D6h)/[10-10]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Hexagonal 6_mmm (D6h)/[2-1-10]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Monoclinic 2_m (C2h)/Monoclinic 2_m (C2h).tiff
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Monoclinic 2_m (C2h)/[001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Monoclinic 2_m (C2h)/[010]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Monoclinic 2_m (C2h)/[100]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Orthorhombic mmm (D2h)/[001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Orthorhombic mmm (D2h)/[010]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Orthorhombic mmm (D2h)/[100]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Tetragonal 4_m (C4h)/Tetragonal 4_m (C4h).tiff
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Tetragonal 4_m (C4h)/[001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Tetragonal 4_m (C4h)/[010]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Tetragonal 4_m (C4h)/[100]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Tetragonal 4_mmm (D4h)/[001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Tetragonal 4_mmm (D4h)/[100]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Tetragonal 4_mmm (D4h)/[110]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Triclinic -1 (Ci)/Triclinic -1 (Ci).tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Triclinic -1 (Ci)/Triclinic -1 (Ci)_FULL.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Triclinic -1 (Ci)/[001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Triclinic -1 (Ci)/[010]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Triclinic -1 (Ci)/[100]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Triclinic -1 (Ci)/ipf_test_image_0_0_1_Red.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Triclinic -1 (Ci)/ipf_test_image_0_1_0_Aqua.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3 (C3i)/Trigonal -3 (C3i).tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3 (C3i)/Trigonal -3 (C3i)_FULL.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3 (C3i)/[-1-120]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3 (C3i)/[0001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3 (C3i)/[2-1-10]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3 (C3i)/ipf_test_image_0_0_1_Red.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3 (C3i)/ipf_test_image_1_0_0_Blue.tiff
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3m (D3d)/Trigonal -3m (D3d).tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3m (D3d)/Trigonal -3m (D3d)_FULL.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3m (D3d)/[0-110]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3m (D3d)/[0001]_pole_figure.tiff
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3m (D3d)/[1-100]_pole_figure.tiff
Binary file not shown.
Binary file not shown.
Binary file modified Data/IPF_Legend/Trigonal -3m (D3d)/ipf_test_image_0_0_1_Red.tiff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67 changes: 33 additions & 34 deletions Source/Apps/generate_ipf_legends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,39 @@ int main(int argc, char* argv[])

std::stringstream ss;
int imageDim = 512;
{
TrigonalOps ops;
auto legend = ops.generateIPFTriangleLegend(imageDim, true);
ss.str("");
ss << k_Output_Dir << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << "_FULL.tiff";
auto result = TiffWriter::WriteColorImage(ss.str(), imageDim, imageDim, 3, legend->getPointer(0));
std::cout << ops.getSymmetryName() << " Result: " << result.first << ": " << result.second << std::endl;

legend = ops.generateIPFTriangleLegend(imageDim, false);
int xStart = imageDim * 0.05F;
int yStart = 0;
int numCols = imageDim * 0.75F;
int numRows = imageDim * 0.65F;
legend = EbsdLib::CropRGBImage<uint8_t>(legend, imageDim, imageDim, xStart, yStart, numCols, numRows);
ss.str("");
ss << k_Output_Dir << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << ".tiff";
result = TiffWriter::WriteColorImage(ss.str(), numCols, numRows, 3, legend->getPointer(0));
std::cout << ops.getSymmetryName() << " Result: " << result.first << ": " << result.second << std::endl;

std::vector<FloatVec3Type> referenceDirections = {
{0.0F, 0.0F, 1.0F}, // Red DONE
{0.0F, 1.0F, 0.0F}, // Green
{-0.5F, std::sqrt(3.0F) / 2.0F, 0.0F}, // Aqua
{2.0F, 1.0F, 0.0F}, // Blue
{0.0F, 1.0F, -1.0F}, // Yellow DONE
{1.0F, -1.0F, 1.0F}, // Pink DONE
{1.0F, 0.0F, 1.0F}, // Flesh
};
std::vector<std::string> colorNames{"Red", "Green", "Aqua", "Blue", "Yellow", "Pink", "Flesh"};
GenerateTestIPFImages(referenceDirections, colorNames, 10);
// Generate Pole Figures for the Input Test Orientations
GeneratePoleFigures(ops, 2);
}

{
TriclinicOps ops;
Expand Down Expand Up @@ -630,40 +663,6 @@ int main(int argc, char* argv[])
GeneratePoleFigures(ops, 2);
}

{
TrigonalOps ops;
auto legend = ops.generateIPFTriangleLegend(imageDim, true);
ss.str("");
ss << k_Output_Dir << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << "_FULL.tiff";
auto result = TiffWriter::WriteColorImage(ss.str(), imageDim, imageDim, 3, legend->getPointer(0));
std::cout << ops.getSymmetryName() << " Result: " << result.first << ": " << result.second << std::endl;

legend = ops.generateIPFTriangleLegend(imageDim, false);
int xStart = imageDim * 0.05F;
int yStart = 0;
int numCols = imageDim * 0.75F;
int numRows = imageDim * 0.65F;
legend = EbsdLib::CropRGBImage<uint8_t>(legend, imageDim, imageDim, xStart, yStart, numCols, numRows);
ss.str("");
ss << k_Output_Dir << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << "/" << EbsdStringUtils::replace(ops.getSymmetryName(), "/", "_") << ".tiff";
result = TiffWriter::WriteColorImage(ss.str(), numCols, numRows, 3, legend->getPointer(0));
std::cout << ops.getSymmetryName() << " Result: " << result.first << ": " << result.second << std::endl;

std::vector<FloatVec3Type> referenceDirections = {
{0.0F, 0.0F, 1.0F}, // Red DONE
{0.0F, 1.0F, 0.0F}, // Green
{-0.5F, std::sqrt(3.0F) / 2.0F, 0.0F}, // Aqua
{2.0F, 1.0F, 0.0F}, // Blue
{0.0F, 1.0F, -1.0F}, // Yellow DONE
{1.0F, -1.0F, 1.0F}, // Pink DONE
{1.0F, 0.0F, 1.0F}, // Flesh
};
std::vector<std::string> colorNames{"Red", "Green", "Aqua", "Blue", "Yellow", "Pink", "Flesh"};
GenerateTestIPFImages(referenceDirections, colorNames, 10);
// Generate Pole Figures for the Input Test Orientations
GeneratePoleFigures(ops, 2);
}

{
TrigonalLowOps ops;
auto legend = ops.generateIPFTriangleLegend(imageDim, true);
Expand Down
2 changes: 1 addition & 1 deletion Source/EbsdLib/Core/Quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class Quaternion

/**
* @brief Conjugate Converts quaternion q into its conjugate
* @return new quaternioin that is the conjugate of the current quaternion
* @return new quaternion that is the conjugate of the current quaternion
*/
Quaternion conjugate() const
{
Expand Down
11 changes: 8 additions & 3 deletions Source/EbsdLib/LaueOps/LaueOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ OrientationD LaueOps::calculateMisorientationInternal(const std::vector<QuatD>&
QuatD qc;
QuatD qr = q1 * (q2.conjugate());
size_t numsym = quatsym.size();
// Loop through all the symmetry operators and find the Axis Angle with the smallest angular part.
for(size_t i = 0; i < numsym; i++)
{
qc = quatsym[i] * qr;
Expand All @@ -211,15 +212,19 @@ OrientationD LaueOps::calculateMisorientationInternal(const std::vector<QuatD>&
}
}
double denom = sqrt((axisAngleMin[0] * axisAngleMin[0] + axisAngleMin[1] * axisAngleMin[1] + axisAngleMin[2] * axisAngleMin[2]));
axisAngleMin[0] = axisAngleMin[0] / denom;
axisAngleMin[1] = axisAngleMin[1] / denom;
axisAngleMin[2] = axisAngleMin[2] / denom;

if(denom == 0.0 || axisAngleMin[3] == 0.0)
{
axisAngleMin[0] = 0.0;
axisAngleMin[1] = 0.0;
axisAngleMin[2] = 1.0;
}
else
{
axisAngleMin[0] = axisAngleMin[0] / denom;
axisAngleMin[1] = axisAngleMin[1] / denom;
axisAngleMin[2] = axisAngleMin[2] / denom;
}

return axisAngleMin;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/EbsdLib/LaueOps/LaueOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class EbsdLib_EXPORT LaueOps
virtual QuatF getNearestQuat(const QuatF& q1f, const QuatF& q2f) const = 0;

/**
* @brief getFZQuat Returns a Quaternioni that lies in the Fundemental Zone (FZ)
* @brief getFZQuat Returns a Quaternion that lies in the Fundamental Zone (FZ)
* @param qr Input Quaternion
* @return
*/
Expand Down
28 changes: 15 additions & 13 deletions Source/EbsdLib/Utilities/TiffWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,29 @@ std::pair<int32_t, std::string> TiffWriter::WriteColorImage(const std::string& f
// Generate the offset into the Image File Directory (ifd) which we are going to write first
constexpr uint32_t ifd_Offset = 8;
outputFile.write(reinterpret_cast<const char*>(&ifd_Offset), sizeof(ifd_Offset));

const int k_NumTags = 12;
std::vector<TIFTAG> tags;
tags.push_back(TIFTAG{0x00FE, 0x0004, 1, 0x00000000}); // NewSubfileType
tags.push_back(TIFTAG{0x0100, 0x0004, 1, width}); // ImageWidth
tags.push_back(TIFTAG{0x0101, 0x0004, 1, height}); // ImageLength
tags.push_back(TIFTAG{0x0102, 0x0003, 1, 8 * sizeof(char)}); // BitsPerSample
tags.push_back(TIFTAG{0x0103, 0x0003, 1, 0x0001}); // Compression
tags.push_back(TIFTAG{0x0106, 0x0003, 1, PHOTOMETRIC_RGB}); // PhotometricInterpretation // For SamplesPerPixel = 3 or 4 (RGB or RGBA)
tags.push_back(TIFTAG{0x00FE, 0x0004, 1, 0x00000000}); // NewSubfileType
tags.push_back(TIFTAG{0x0100, 0x0004, 1, width}); // ImageWidth
tags.push_back(TIFTAG{0x0101, 0x0004, 1, height}); // ImageLength
tags.push_back(TIFTAG{0x0102, 0x0003, 1, 8 * sizeof(char)}); // BitsPerSample
tags.push_back(TIFTAG{0x0103, 0x0003, 1, 0x0001}); // Compression
tags.push_back(TIFTAG{0x0106, 0x0003, 1, PHOTOMETRIC_RGB}); // PhotometricInterpretation // For SamplesPerPixel = 3 or 4 (RGB or RGBA)
// Now compute the offset to the image data so that we can put that into the tag.
// The math on this ONLY Works if we have 11 total Tags.
// IF YOU ADD MORE TAGS, YOU NEED TO ADJUST THE NEXT LINE OF CODE
int32_t imageDataOffset = static_cast<int32_t>(8 + (k_NumTags * 12) + 6); // Header + tags + IDF Tag entry count and Next IFD Offset
tags.push_back(TIFTAG{0x0111, 0x0004, 1, imageDataOffset}); // StripOffsets

tags.push_back(TIFTAG{0x0112, 0x0003, 1, 1}); // Orientation
tags.push_back(TIFTAG{0x0115, 0x0003, 1, samplesPerPixel}); // SamplesPerPixel
tags.push_back(TIFTAG{0x0116, 0x0004, 1, height}); // RowsPerStrip
tags.push_back(TIFTAG{0x0117, 0x0004, 1, width * height * samplesPerPixel}); // StripByteCounts

// TIFTAG XResolution;
// TIFTAG YResolution;
// TIFTAG ResolutionUnit;
tags.push_back(TIFTAG{0x011c, 0x0003, 1, 0x0001}); // PlanarConfiguration

// Now compute the offset to the image data so that we can put that into the tag.
// THESE NEXT 2 LINES MUST BE THE LAST TAG TO BE PUSHED BACK INTO THE VECTOR OR THE MATH WILL BE WRONG
int32_t imageDataOffset = static_cast<int32_t>(8 + ((tags.size() + 1) * 12) + 6); // Header + tags + IDF Tag entry count and Next IFD Offset
tags.push_back(TIFTAG{0x0111, 0x0004, 1, imageDataOffset}); // StripOffsets
tags.push_back(TIFTAG{0x011c, 0x0003, 1, 0x0001}); // PlanarConfiguration // 284

// Write the number of tags to the IFD section
uint16_t numEntries = static_cast<uint16_t>(tags.size());
Expand Down

0 comments on commit c705a3b

Please sign in to comment.