how to assign 1D spectra to imagestack

45 views Asked by At

any idea why this does not work?

DM::Image im2D = DM::RealImage("2D", 4, 2048);
DM::Image im3D= DM::RealImage("3D", 4, 2048, 9, 9);

PlugIn::ImageDataLocker im2D_LLl(im2D, PlugIn::ImageDataLocker::lock_data_CONTIGUOUS);
float *im2D_data = (float*)(im2D_LLl.get_image_data().get_data());
for (int i = 0; i <2048; i++) *Im2D_data++ = i;

Imaging::DataSlice planeSlice;
long xi=0, yi=0;
planeSlice = Imaging::DataSlice(Imaging::DataIndex(xi, yi, 0), Imaging::DataSlice::Slice1(2, 2048, 1));

DM::SliceImage(im3D, planeSlice) = im2D;

im3D is not changed, giving only zeros. In DM scripting side this would be:

slice1(im3D, 0,0,0,2,2048,1) = im2D

which works fine.

1

There are 1 answers

1
BmyGuest On

I'm somewhat confused by your example code.
It seems you create a 3D image of XYZ = 2048 x 9 x 9
but then slice it along dim=2 (z) for 2048 channels (it has only 9!)

The same is true for you script code. slice1 creates a 1D image along the dimension 2.

I think you've meant to use

slice2( img3D, 0,0,0, 0,9,1, 1,9,1 ) = img2d

Or, if you really meant to do spectrum-insertion (as you title suggests), you want some better named variables for sure.


Script example of creating a stack and filling it plane-wise:

image stack := realimage("Stack of 2048 2D images 9x9",4,9,9,2048)
for ( number i=0; i<2048; i++ ){
    image plane2D := Realimage("2D plane 9x9",4,9,9)
    plane2D = iradius + random()
    stack.Slice2(0,0,i, 0,9,1, 1,9,1 ) = plane2D
}
stack.ShowImage()

Script example of creating a stack and filling it spectrum-wise:

image stack := realimage("Stack of 2048 2D images 9x9",4,9,9,2048)
for ( number i=0; i<9; i++ ){
    for ( number j=0; j<9; j++ ){
        image spec1D:= Realimage("1D spectrum 2048",4,2048)
        spec1D = iradius + random()
        stack.Slice1(i,j,0, 2,2048,1 ) = spec1D
    }
}
stack.ShowImage()

As for the SDK code: When you create an image locker to change the data, make sure you use

im2d.DataChanged();

to finalize and update the image object.