/*-------------------------------------------------------------------------------------

Hit ctrl-enter to execute.

Description:

	A simple program illustrating a projected 1D line plot of a 2D image through
	a specified angle through use of the icol intrinsic variable and the warp function

	Copyright © 2001 Gatan Inc.

-------------------------------------------------------------------------------------*/

// Grab the front image
image img := GetFrontImage()	
					
// Check it is a 2D image; if not, throw an appropriate error
if (img.ImageGetNumDimensions() != 2) 					
	Throw("A 2D image must be front-most to perform this operation.\n")

// Get the height of the source image
number height = img.ImageGetDimensionSize( 1 )			

// Request the desired projection angle from the user
// exitting if cancel hit.
number angle = 45
if (!GetNumber( "Please enter projection angle (0-89°)", angle , angle ))
	exit(0)	
				
// Ensure the angle variable is in the range 0-90; if not, clip it so it is
// then convert to radians
angle = clip(angle, 0, 89.)								
number angle_rad = angle/360.*2*3.14159	
				
// Create the destination projection plot image, and perform the warp transform.  
// This has the effect of rotating the image through the specified angle, 
// and projecting the result onto the y-axis
image projection := RealImage("Projection (" + angle + "°)", 4, height)		
projection = warp(img, tan(angle_rad)*icol, icol)		

// Display the image.
showimage(projection)									