{ Date: Wed, 5 Jan 1994 20:20:12 -0800 (PST) From: Glen Macdonald Subject: a rotational align macro To: Wayne Rasband A macro set is included below to perform simple rotational and x-y registration of two images. there has been a lot of sophisticated methods discussed for doing rotational alignments, but I had a deadline to meet. This is very basic, but wholly adequate for counting double labelled objects immunolabelled in two adjacent semithin sections or counting objects with a physical disector method. This is the alignment kernel from a larger macro set for doing double label counts. I think most of the extraneous variables and commands have been removed. Anyway, it works. Many thanks to Mark Vivino for posting his image translation macro, I used most of it here. To use: 1. grab the first image (or open a file); 2. draw a line from left to right between two landmarks; 3. press "4" to mark the image (a copy is created entitled "Register To:windowname"); 4. get the next image, this is the one that will be rotated and pasted onto the "Register to" image; 5. draw a line from left to right between the landmarks, as if you are facing the landmarks from the same direction as you were with the first image; 6. Press "5", this will create a rotated copy entitled "Image to be Registered"; 7. If you are happy wth the results Press "7", otherwise delete and remark the second image; 8. The rotated image can be dragged in X and Y to complete the alignment. Glen MacDonald Hearing Development Laboratories RL-30 University of Washington Seattle, WA 98195 (206)543-8360 glenmac@u.washington.edu } ************************************************************** {Image rotation macro; Glen MacDonald, for the Child Development and Mental Retardation Center, University of Washington, Seattle, WA. November 22, 1993, rev. Jan. 3, 1994. Many thanks to Mark Vivino for posting the x-y image registration macros} var {global variables} x1,x2,y1,y2,width,height,LineWidth,firstAngle,dx,dy,SecondAngle,deltaAngle,ThisAngle,SinA:real; x,y,ImageToRegister, RegistrationImage:integer; OrigTop,OrigLeft,OrigWidth,OrigHeight,stage:integer; Procedure GetSinA; var Hypot:real; begin Hypot:=sqrt(sqr(dx)+sqr(dY)); {gives the hypotenuse of the angle} SinA:=dY/Hypot; ThisAngle:=rAngle[rCount]; {grab the angle for this image} if ((SinA=0) and (dX<0)) then ThisAngle:=0 else if ((SinA<0) or ((SinA=0) and (dX>0))) then ThisAngle:=(180-rAngle[rCount]) else ThisAngle:=((rAngle[rCount])*(-1)); end; Procedure FindLineMidPoint; begin GetLine(x1,y1,x2,y2,LineWidth); {get x,y coords. of line ends} if LineWidth = 0 then begin putMessage('You must draw a line from left to right between two landmarks.'); exit; end; measure; dx:=x1-x2; dy:=y1-y2; GetSinA; end; macro 'Mark First Image [4]'; var regpicname:string; begin SetOptions('Angle'); regpicname:=WindowTitle; SelectAll; Duplicate('Register to:' regpicname); RestoreRoi; if WindowTitle='Camera' then begin PutMessage('The active window cannot be "Camera".'); exit; end; RegistrationImage:=pidnumber; FindLineMidPoint; firstAngle:=ThisAngle; PutMessage('Now go to the image to be aligned to this one.'); end; macro 'Mark and Rotate Second Image [5]'; begin FindLineMidPoint; secondAngle:=ThisAngle; deltaAngle:=(firstAngle-secondAngle); SelectAll; ScaleandRotate(1,1,deltaangle); SetPicName('Image to Register'); SelectAll; GetROI(OrigLeft,OrigTop,OrigWidth,OrigHeight); if OrigWidth=0 then begin PutMessage('Use Select All or create an ROI on the image you want registered.'); exit; end; ImageToRegister := PidNumber; ShowPasteControl; Copy; SelectPic(RegistrationImage); Showmessage('Run the next macro.'); RestoreRoi; end; macro 'Register the Images [6]'; begin Showmessage('Move the ROI to the visual registration point.'); Paste; SetOption; DoXOr; end;