Skip to content

ApplyGeoInReconstructionMetadata

Adrian Quintana edited this page Dec 11, 2017 · 1 revision

Apply shifts and mirrors to a reconstruction metadata to produce aligned images

Apply shifts and mirrors to the images of a reconstruction metadata so that the aligned images can be aligned with no shift and no mirror. The program is passed the reconstruction metadata and the rootname of the output. The output contains two files, a metadata with the Euler angles and the names of the images and the stack with all the aligned images.

Invoke the program as


xmipp_compile preprocessImages.cpp
./preprocessImages angles.xmd aligned


The reconstruction from the aligned.xmd and the angles.xmd should be identical


xmipp_reconstruct_fourier -i angles.xmd -o angles.vol
xmipp_reconstruct_fourier -i aligned.xmd -o aligned.vol


The preprocessImages.cpp is


#include <data/xmipp_image.h>

int main(int argc, char **argv)
{
    try {
        FileName fnSel=argv[1];
        FileName fnRoot=argv[2];
        MetaData md;
        md.read(fnSel);
        
        FileName fnImg;
        Image<double> I, Iout;
        Matrix2D<double> A;
        size_t idx=1;
        FOR_ALL_OBJECTS_IN_METADATA(md)
        {
            md.getValue(MDL_IMAGE,fnImg,__iter.objId);
            I.read(fnImg);
            
            double shiftX, shiftY;
            bool flip;
            md.getValue(MDL_SHIFT_X,shiftX,__iter.objId);
            md.getValue(MDL_SHIFT_Y,shiftY,__iter.objId);
            md.getValue(MDL_FLIP,flip,__iter.objId);
            
            A.initIdentity(3);
            A(0,2)=shiftX;
            A(1,2)=shiftY;
            if (flip)
            {
                md.setValue(MDL_FLIP,false,__iter.objId);
                A(0,0)*=-1;
            }
            md.getValue(MDL_IMAGE,fnImg,__iter.objId);
            I.read(fnImg);
            I().setXmippOrigin();
            
            applyGeometry(BSPLINE3,Iout(),I(),A,IS_NOT_INV,DONT_WRAP);
            Iout.write(fnRoot+".stk",idx,true,WRITE_REPLACE);
            md.setValue(MDL_IMAGE,formatString("%05d@%s.stk",idx,fnRoot.c_str()),__iter.objId);
            md.setValue(MDL_IMAGE_ORIGINAL,fnImg,__iter.objId);
            md.setValue(MDL_SHIFT_X,0.0,__iter.objId);
            md.setValue(MDL_SHIFT_Y,0.0,__iter.objId);
            
            idx++;
        }
        md.write(fnRoot+".xmd");
    } catch (XmippError XE)
    {
        std::cout << XE << std::endl;
    }
}


Clone this wiki locally