Skip to content

Commit

Permalink
PAR/REC field map calibrated in Hz given name _fieldmaphz (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Dec 9, 2020
1 parent f827a59 commit 7f9b266
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
23 changes: 17 additions & 6 deletions console/nii_dicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ struct TDICOMdata clear_dicom_data() {
d.overlayStart[i] = 0;
d.isHasOverlay = false;
d.isPrivateCreatorRemap = false;
d.isRealIsPhaseMapHz = false;
d.numberOfImagesInGridUIH = 0;
d.phaseEncodingRC = '?';
d.patientSex = '?';
Expand Down Expand Up @@ -2017,9 +2018,10 @@ int kbval = 33; //V3: 27
}
if (cols[kImageType] == 0) d.isHasMagnitude = true;
if (cols[kImageType] != 0) d.isHasPhase = true;
if ((isSameFloat(cols[kImageType],18)) && (!isTypeWarning)) {
printWarning("Field map in Hz will be saved as the 'real' image.\n");
isTypeWarning = true;
if (isSameFloat(cols[kImageType],18)) {
//printWarning("Field map in Hz will be saved as the 'real' image.\n");
//isTypeWarning = true;
d.isRealIsPhaseMapHz = true;
} else if (((cols[kImageType] < 0.0) || (cols[kImageType] > 4.0)) && (!isTypeWarning)) {
printError("Unknown type %g: not magnitude[0], real[1], imaginary[2] or phase[3].\n", cols[kImageType]);
isTypeWarning = true;
Expand Down Expand Up @@ -2107,15 +2109,24 @@ int kbval = 33; //V3: 27
bool isReal = (cols[kImageType] == 1);
bool isImaginary = (cols[kImageType] == 2);
bool isPhase = (cols[kImageType] == 3);
if (cols[kImageType] == 18) {
isReal = true;
d.isRealIsPhaseMapHz = true;
}
if (cols[kImageType] == 4) {
if (!isType4Warning) {
printWarning("Unknown image type (4). Be aware the 'phase' image is of an unknown type.\n");
isType4Warning = true;
}
isPhase = true; //2019
}
if ((cols[kImageType] < 0.0) || (cols[kImageType] > 3.0))
if ((cols[kImageType] != 18) && ((cols[kImageType] < 0.0) || (cols[kImageType] > 3.0))) {
if (!isType4Warning) {
printWarning("Unknown image type (%g). Be aware the 'phase' image is of an unknown type.\n", round(cols[kImageType]));
isType4Warning = true;
}
isReal = true; //<- this is not correct, kludge for bug in ROGERS_20180526_WIP_B0_NS_8_1.PAR
}
if (isReal) vol += num3DExpected;
if (isImaginary) vol += (2*num3DExpected);
if (isPhase) vol += (3*num3DExpected);
Expand Down Expand Up @@ -5171,7 +5182,7 @@ uint32_t kSequenceDelimitationItemTag = 0xFFFE +(0xE0DD << 16 );
//issue 256: Philips files report real ComplexImageComponent but Magnitude ImageType https://github.com/rordenlab/dcm2niix/issues/256
isPhase = false;
isReal = false;
isImaginary = false;
isImaginary = false;
isMagnitude = false;
//see Table C.8-85 http://dicom.nema.org/medical/Dicom/2017c/output/chtml/part03/sect_C.8.13.3.html
if ((buffer[lPos]=='R') && (toupper(buffer[lPos+1]) == 'E'))
Expand All @@ -5185,7 +5196,7 @@ uint32_t kSequenceDelimitationItemTag = 0xFFFE +(0xE0DD << 16 );
//not mutually exclusive: possible for Philips enhanced DICOM to store BOTH magnitude and phase in the same image
if (isPhase) d.isHasPhase = true;
if (isReal) d.isHasReal = true;
if (isImaginary) d.isHasImaginary = true;
if (isImaginary) d.isHasImaginary = true;
if (isMagnitude) d.isHasMagnitude = true;
break;
case kAcquisitionContrast:
Expand Down
4 changes: 2 additions & 2 deletions console/nii_dicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static const uint8_t MAX_NUMBER_OF_DIMENSIONS = 8;
bool isReal[kMaxDTI4D];
bool isImaginary[kMaxDTI4D];
bool isPhase[kMaxDTI4D];
float repetitionTimeExcitation, repetitionTimeInversion;
float repetitionTimeExcitation, repetitionTimeInversion;
};

#ifdef _MSC_VER //Microsoft nomenclature for packed structures is different...
Expand Down Expand Up @@ -192,7 +192,7 @@ static const uint8_t MAX_NUMBER_OF_DIMENSIONS = 8;
char institutionAddress[kDICOMStrLarge], imageComments[kDICOMStrLarge];
uint32_t dimensionIndexValues[MAX_NUMBER_OF_DIMENSIONS];
struct TCSAdata CSA;
bool isPrivateCreatorRemap, isHasOverlay, isEPI, isIR, isPartialFourier, isDiffusion, isVectorFromBMatrix, isRawDataStorage, isGrayscaleSoftcopyPresentationState, isStackableSeries, isCoilVaries, isNonParallelSlices, isSegamiOasis, isXA10A, isScaleOrTEVaries, isScaleVariesEnh, isDerived, isXRay, isMultiEcho, isValid, is3DAcq, is2DAcq, isExplicitVR, isLittleEndian, isPlanarRGB, isSigned, isHasPhase, isHasImaginary, isHasReal, isHasMagnitude,isHasMixed, isFloat, isResampled, isLocalizer;
bool isRealIsPhaseMapHz, isPrivateCreatorRemap, isHasOverlay, isEPI, isIR, isPartialFourier, isDiffusion, isVectorFromBMatrix, isRawDataStorage, isGrayscaleSoftcopyPresentationState, isStackableSeries, isCoilVaries, isNonParallelSlices, isSegamiOasis, isXA10A, isScaleOrTEVaries, isScaleVariesEnh, isDerived, isXRay, isMultiEcho, isValid, is3DAcq, is2DAcq, isExplicitVR, isLittleEndian, isPlanarRGB, isSigned, isHasPhase, isHasImaginary, isHasReal, isHasMagnitude,isHasMixed, isFloat, isResampled, isLocalizer;
char phaseEncodingRC, patientSex;
};

Expand Down
11 changes: 8 additions & 3 deletions console/nii_dicom_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,8 @@ tse3d: T2*/
fprintf(fp,"\", \"REAL");
if ((d.isHasImaginary) && ((d.manufacturer == kMANUFACTURER_GE) || (strstr(d.imageType, "_IMAGINARY_") == NULL)) )
fprintf(fp,"\", \"IMAGINARY");
if ((d.isRealIsPhaseMapHz))// && ((d.manufacturer == kMANUFACTURER_GE) || (strstr(d.imageType, "_IMAGINARY_") == NULL)) )
fprintf(fp,"\", \"FIELDMAPHZ");
fprintf(fp, "\"],\n");
}
if (d.isDerived) //DICOM is derived image or non-spatial file (sounds, etc)
Expand Down Expand Up @@ -2667,7 +2669,10 @@ int nii_createFilename(struct TDICOMdata dcm, char * niiFilename, struct TDCMopt
if ((isAddNamePostFixes) && (dcm.isHasImaginary)) {
strcat (outname,"_imaginary"); //has phase map
}
if ((isAddNamePostFixes) && (dcm.isHasReal)) {
if ((isAddNamePostFixes) && (dcm.isHasReal) && (dcm.isRealIsPhaseMapHz)) {
strcat (outname,"_fieldmaphz"); //has field map
}
if ((isAddNamePostFixes) && (dcm.isHasReal) && (!dcm.isRealIsPhaseMapHz)) {
strcat (outname,"_real"); //has phase map
}
if ((isAddNamePostFixes) && (dcm.isHasPhase)) {
Expand Down Expand Up @@ -6090,9 +6095,9 @@ bool isSameSet (struct TDICOMdata d1, struct TDICOMdata d2, struct TDCMopts* opt
//}
return true; //we will stack these images, even if they differ in the following attributes
}
if ((d1.isHasImaginary != d2.isHasImaginary) || (d1.isHasPhase != d2.isHasPhase) || ((d1.isHasReal != d2.isHasReal))) {
if ((d1.isHasImaginary != d2.isHasImaginary) || (d1.isHasPhase != d2.isHasPhase) || (d1.isHasReal != d2.isHasReal)) {
if (!warnings->phaseVaries)
printMessage("Slices not stacked: some are phase/real/imaginary maps, others are not. Instances %d %d\n", d1.imageNum, d2.imageNum);
printMessage("Slices not stacked: some are phase/real/imaginary/phase maps, others are not. Instances %d %d\n", d1.imageNum, d2.imageNum);
warnings->phaseVaries = true;
return false;
}
Expand Down

0 comments on commit 7f9b266

Please sign in to comment.