脚本命令通过校准水平对齐切片

时间:2015-10-10 00:44:47

标签: dm-script

是否有脚本命令可以在LinePlotImageDisplay中指定特定切片并通过校准(或未校准(通道))操作水平对齐切片?

2 个答案:

答案 0 :(得分:2)

以下scipt是​​基于BmyGuest提供的示例代码的完整植入。它将通过校准或通道(即未校准)水平对齐LinePlotImageDisplay中的所有切片。

class SliceAlignment : object {
    number true, false;     // boolean
    image imgLPID;
    imageDisplay LPID;      // line plot image display

number CalculateImageToGroupTransformFactors( object self, image slice_src, image slice_ref, number &relOff, number &relScale ) {
    number origin_ref, scale_ref, origin_src, scale_src;
    string unit_ref, unit_src;
    number calFMT = 0;          // origin is expressed in calibrated unit
    //
    slice_src.ImageGetDimensionCalibration( 0, origin_src, scale_src, unit_src, calFMT );
    slice_ref.ImageGetDimensionCalibration( 0, origin_ref, scale_ref, unit_ref, calFMT );
    //
    relScale = scale_src / scale_ref;
    relOff = (origin_src - origin_ref) / scale_ref ;
    // check if both images are calibrated in same unit
    if( unit_src != unit_ref ) return false
    return true;
};

void AlignNthSliceHorizontallyByChannel( object self, number slice_idx ) {
    // get current reference slice index
    number refSlice_idx = LPID.LinePlotImageDisplayGetSlice();
    // get slice ID's (as objects)
    object slice_ref = LPID.ImageDisplayGetSliceIDByIndex(refSlice_idx);
    object slice_src = LPID.ImageDisplayGetSliceIDByIndex(slice_idx);
    number int_offset = 0, int_scale = 1.0;         // vertical (intensity) offset and scaling factors
    number pos_offset = 0, pos_scale = 1.0;         // horizontal (position) offset and scaling factors
    LPID.LinePlotImageDisplaySetImageToGroupTransform( slice_src, slice_ref, int_offset, int_scale, pos_offset, pos_scale );
};  

void AlignNthSliceHorizontallyByCalibration( object self, number slice_idx ) {
    // get current reference slice index
    number refSlice_idx = LPID.LinePlotImageDisplayGetSlice();
    // get slice ID's (as objects)
    object slice_ref = LPID.ImageDisplayGetSliceIDByIndex(refSlice_idx);
    object slice_src = LPID.ImageDisplayGetSliceIDByIndex(slice_idx);
    number int_offset = 0, int_scale = 1.0;         // vertical (intensity) offset and scaling factors
    number pos_offset, pos_scale;                   // horizontal (position) offset and scaling factors
    number unit_check = self.CalculateImageToGroupTransformFactors( imgLPID{slice_idx}, imgLPID{refSlice_idx}, pos_offset, pos_scale );
    if( unit_check == false ) {
        string prompt = "slice #" + slice_idx + " [" + LPID.ImageDisplayGetSliceLabelById( LPID.ImageDisplayGetSliceIDByIndex(slice_idx) ) + "] is calibrated in different unit!";
        if( !ContinueCancelDialog( prompt ) ) return
    };
    LPID.LinePlotImageDisplaySetImageToGroupTransform( slice_src, slice_ref, int_offset, int_scale, pos_offset, pos_scale );
    return;
};

void AlignAllSlicesHorizontallyByChannel( object self ) {
    number nSlices = LPID.LinePlotImageDisplayCountSlices();
    for( number idx = 0; idx < nSlices; idx++ ) self.AlignNthSliceHorizontallyByChannel( idx );
    return;
};

void AlignAllSlicesHorizontallyByCalibration( object self ) {
    number nSlices = LPID.LinePlotImageDisplayCountSlices();
    for( number idx = 0; idx < nSlices; idx++ ) self.AlignNthSliceHorizontallyByCalibration( idx );
    return;
};

object init( object self, image img ) {
    // check if the image display is correct type
    imgLPID := img;
    LPID = imgLPID.ImageGetImageDisplay(0);
    if( LPID.ImageDisplayGetDisplayType() != 3 ) throw( "Please choose a valid line plot display" );
    return self;
};

SliceAlignment( object self ) {
    true = 1; false = 0;
    result( "SliceAlignment [obj ID:" + self.ScriptObjectGetID().hex() + "] constructured\n" );
};

~SliceAlignment( object self ) {
    result( "SliceAlignment [obj ID:" + self.ScriptObjectGetID().hex() + "] destructured\n\n" );
}; };

{; object objAlign = alloc(SliceAlignment);
objAlign.init( GetFrontImage() );
if( OptionDown() ) objAlign.AlignAllSlicesHorizontallyByChannel();
else objAlign.AlignAllSlicesHorizontallyByCalibration(); };

答案 1 :(得分:1)

不,没有单一的便利性&#39;命令实现这种对齐。您必须自己创建相应的功能,从读取切片校准和设置其显示坐标系。您可能会发现FELMI主页上的以下(旧)教程PDF可能很有用:

SlicesInLinePlotDisplay.pdf

以下示例脚本也可能有用。它显示了一个切片如何相对于另一个切片对齐。 (仅在X轴上)

// All Slices in a LinePlot are grouped into a single 'group'
// Slices can be moved relative to each other by specifying their image-to-group transform, 
// and the whole image (i.e. the group) can be moved with respect to the display using the group-to-display transform.
// To set the image-to-group transform of the slice specified by 'slice_id', with respect to the slice specified by 'ref_id' 
// use the command: 
//  LinePlotImageDisplaySetImageToGroupTransform( LinePlotImageDisplay lpid, ScriptObject slice_id, ScriptObject ref_id, double  off_val, double  scale_val, double  off_dim_0, double scale_dim_0 )

/*********************************************************/
// Create 2 LinePlots and add them into one display
// (Initially they are aligned by their calibrations)
number sc1 = 1
number of1 = -50
number sc2 = 2
number of2 = -20

image sl1 := realImage("S1",4,300)
image sl2 := realImage("S2",4,300)
sl1 = (iwidth-icol)/iwidth
sl2 = (iwidth-icol)/iwidth
sl1[0,50,1,60] = 1
sl1[0,250,1,260] = 1
sl2[0,10,1,15] = 1
sl2[0,110,1,115] = 1
// Adding Calibrations
sl1.ImageSetDimensionCalibration(0,of1,sc1,"CH",0)
sl2.ImageSetDimensionCalibration(0,of2,sc2,"CH",0)

sl1.DisplayAt(20,30)
sl2.DisplayAt(750,30)
OKDialog( "Put into one Display" )

imageDisplay disp = sl1.ImageGetImageDisplay(0) 
disp.ImageDisplayAddImage( sl2, "S2")                       // When added like this, the slices are automatically aligned by their respective calibration!
disp.LinePlotImageDisplaySetDoAutoSurvey( 0, 0 )
object ref_id = disp.ImageDisplayGetSliceIDByIndex(0)       // Slice 0
object slice_id = disp.ImageDisplayGetSliceIDByIndex(1)     // Slice 1

OKDialog("Now align by channels (i.e. undo any relative sclice alignment)")
// Simply set the relative "shifts" and "scales" to 0 and 1.
disp.LinePlotImageDisplaySetImageToGroupTransform( slice_id, ref_id, 0, 1, 0, 1 )   

OKDialog("Now align by chalibration ")
number relScale = sc2/sc1
number relOff = of2-of1
disp.LinePlotImageDisplaySetImageToGroupTransform( slice_id, ref_id, 0, 1, relOff, relScale )