如何通过脚本旋转3D光谱图像?

时间:2018-08-31 20:47:28

标签: image-rotation dm-script

我想找到与绕X轴或Y轴旋转的rotation(image,degree)脚本命令等效的命令(我只需要旋转90º)。我知道我可以使用工具菜单来执行此操作,但是如果我可以找到一个命令或函数来使用脚本来执行此操作,则会更快。

提前谢谢!

2 个答案:

答案 0 :(得分:1)

  

一开始使用<button mat-raised-button routerLink='Home' routerLinkActive="active"> Home </button> 命令可能会造成混淆,因此这是一个   有关使用该命令围绕坐标轴旋转的详细说明   X轴。

此示例说明了如何使用import pandas as pd #read in first set of data, start from the beginning, read 10 lines df1=pd.read_csv('exfile.txt', sep=" ",skiprows=None,nrows=10) #read in the second set of data, do not start at the beginning of file but skip 11 rows, read the next 10 lines df2=pd.read_csv('exfile.txt', sep=" ",skiprows=11,nrows=10) #choose any two cols, for example: print(df1['TC']) print(df2['13TeV']) 命令围绕其X轴(沿X方向)顺时针旋转3D数据。

Slice命令在现有数据数组上指定一个新视图。

  • 它首先指定原点像素,即在新视图中将由(0,0,0)表示的原始数据中的坐标。

  • 然后为新的三个轴指定采样方向,长度和步长。
    第一个三元组指定(原始数据中的)坐标沿新图像的x方向如何变化,第二个三元组用于新图像的y方向,最后一个三元组用于新图像的z方向。

因此,围绕x轴的旋转可以想象为: Rotation around X

对于“重采样”数据:

  • 新的(旋转的)数据的起源是原始数据的数据点(0,0,SZ-1)。
  • 它的X方向保持不变,即新数据中X的一个步长会使原始数据中的坐标三联体也增加(1,0,0)。步长为1。
  • 它的Y方向本质上是以前的负Z方向,即,新数据中Y的一个步长也会使原始数据中的坐标三联体也增加(0,0,-1)。 >因此,SZ步长为-1。
  • 它的Z方向本质上是以前的Y方向,即在新数据中Z的一个步长会使原始数据中的坐标三联体增加(0,1,0)。
    因此, SY步长为1。

因此,要绕X轴顺时针旋转,命令为:
Slice3

此命令将在相同的数据上创建一个新的 view (即,不使用任何其他内存。)因此,将旋转后的图像作为新图像获取(数据值应对齐)在内存中),则可以将此视图克隆克隆到Slice3

的新图像中

下面的脚本总共作为示例:

img.Slice3( 0,0,SZ-1, 0,SX,1, 2,SZ,-1, 1,SY,1 )


以下方法执行90度旋转:

ImageClone()

可以使用// Demo of rotating 3D data orthogonally around the X axis // This is done by resampling the data using the Slice3 command // Creation of test image with regcognizeable pattern number SX = 100 number SY = 30 number SZ = 50 image img := RealImage("Test",4, SX,SY,SZ) // trig. modulated linear increase in X img = icol/iwidth* sin( icol/(iwidth-1) * 5 * Pi() ) **2 // Simple linear increase in Y img += (irow/iheight) * 2 // Modulation of values in Z // (doubling values for index 0,1, 3, 4, 9, 16, 25, 36, 49) img *= (SQRT(iplane) == trunc(SQRT(iplane)) ? 2 : 1 ) img.ShowImage() // Show captions. Image coordinate system is // Origin (0,0,0) in top-left-front most pixel // X axis goes left to right // Y axis goes top to down // Z axis goes front to back img.ImageSetDimensionCalibration(0,0,1,"orig X",0) img.ImageSetDimensionCalibration(1,0,1,"orig Y",0) img.ImageSetDimensionCalibration(2,0,1,"orig Z",0) img.ImageGetImageDisplay(0).ImageDisplaySetCaptionOn(1) // Rotation around X axis, clockwise looking along X // X --> X` (unchanged) // Y --> Z' // Z --> -Y' // old origin moves to bottom-left-front most // This means for "new" sampling: // Specify sampling starting point: // New origin (0,0,0)' will be value which was at (0,0,SZ-1) // Going one step in X' in the new data, will be like going one step in X // Going one step in Y' in the new data, will be like going one step backwards in Z // Going one step in Z' in the new data, will be like going one step in Y image rotXCW := img.Slice3( 0,0,SZ-1, 0,SX,1, 2,SZ,-1, 1,SY,1 ).ImageClone() rotXCW.SetName("rotated X, CW") rotXCW.ShowImage() rotXCW.ImageGetImageDisplay(0).ImageDisplaySetCaptionOn(1) // Functions for 90degree rotations of data image RotateXCW( image input ) { number SX,SY,SZ input.Get3DSize(SX,SY,SZ) return input.Slice3( 0,0,SZ-1, 0,SX,1, 2,SZ,-1, 1,SY,1 ).ImageClone() } image RotateXCCW( image input ) { number SX,SY,SZ input.Get3DSize(SX,SY,SZ) return input.Slice3( 0,SY-1,0, 0,SX,1, 2,SZ,1, 1,SY,-1 ).ImageClone() } image RotateYCW( image input ) { number SX,SY,SZ input.Get3DSize(SX,SY,SZ) return input.Slice3( SX-1,0,0, 2,SZ,1, 1,SY,1, 0,SX,-1 ).ImageClone() } image RotateYCCW( image input ) { number SX,SY,SZ input.Get3DSize(SX,SY,SZ) return input.Slice3( 0,0,SZ-1, 2,SZ,-1, 1,SY,1, 0,SX,1 ).ImageClone() } image RotateZCW( image input ) { number SX,SY,SZ input.Get3DSize(SX,SY,SZ) return input.Slice3( 0,SY-1,0, 1,SY,-1, 0,SX,1, 2,SZ,1 ).ImageClone() } image RotateZCCW( image input ) { number SX,SY,SZ input.Get3DSize(SX,SY,SZ) return input.Slice3( SX-1,0,0, 1,SY,1, 0,SX,-1, 2,SZ,1 ).ImageClone() } 完成围绕z轴的旋转。但是请注意,这些命令将不适应图像的尺寸校准,而Slice3命令将适应。

答案 1 :(得分:0)

对于纯正交旋转,最简单(也是最快)的方法是使用“ slice”命令,即对3D图像使用“ slice3”。 事实证明,最新版本的GMS在帮助文档中有一个示例,因此我只是在此处复制粘贴代码:

number sx = 10
number sy = 10
number sz = 10

number csx, csy, csz 
image img3D := RealImage( "3D", 4, sx, sy, sz )
img3D = 1000 + sin( 2*PI() * iplane/(idepth-1) ) * 100 + icol * 10  + irow
img3D.ShowImage()

// Rotate existing image
if ( OKCancelDialog( "Rotate clockwise (each plane)\n= Rotate block around z-axis" ) )
 img3D.RotateRight()



if ( OKCancelDialog( "Rotate counter-clockwise (each plane)\n= Rotate block around z-axis" ) )
 img3D.RotateLeft()


if ( OKCancelDialog( "Rotate block counter-clockwise around X-axis" ) )
{
 // Equivalent of sampling the data anew
 // x-axis remains 
 // y- and z-axis change their role
 img3D.Get3DSize( csx, csy, csz )        // current size along axes
 img3D = img3D.Slice3( 0,0,0, 0,csx,1, 2,csz,1, 1,csy,1 )
}

if ( OKCancelDialog( "Rotate block clockwise around X-axis" ) )
{
 // Equivalent of sampling the data anew
 // x-axis remains 
 // y- and z-axis change their role
 img3D.Get3DSize( csx, csy, csz )        // current size along axes
 img3D = img3D.Slice3( 0,csy-1,csz-1, 0,csx,1, 2,csz,-1, 1,csy,-1 )
}

if ( OKCancelDialog( "Rotate 30 degree (each plane)\n= Rotate block around z-axis" ) )
{
 number aDeg = 30
 number interpolMeth = 2
 number keepSize = 1
 image rotImg := img3D.Rotate( 2*Pi()/360 * aDeg, interpolMeth, keepSize )
 rotImg.ShowImage()
}

您可能还希望查看this answer,以获取有关子采样和在数据上创建不同视图的更多信息。