Author Topic: Using the Image assign() method  (Read 4320 times)

Offline Bob Andersson

  • Member
  • *
  • Posts: 67
Using the Image assign() method
« on: 2013 January 05 05:30:27 »
Hi folks,

Just in case someone else can't figure out why the Image assign() method can produce monochrome images from colour originals here's the trick:

Code: [Select]
   var img = targetView.image; // targetView is of type ImageWindow
   var clippedWindow = new ImageWindow (1, 1, 1, img.bitsPerSample, img.sampleType == SampleType_Real, img.isColor, "nameofyourchoice");
   with (clippedWindow.mainView)
   {
      img.firstSelectedChannel = 0;
      img.lastSelectedChannel = img.numberOfChannels - 1;
      beginProcess(UndoFlag_NoSwapFile);
      image.assign(img);
      endProcess();
   }

It took me far more time than it should have to realise I needed to set the values of "firstSelectedChannel" and "lastSelectedChannel" before calling assign(). Obvious to the experienced PI scriptwriters, perhaps, but to a newbie like me still on his first script the default behaviour where, on a freshly opened RGB image, both "firstSelectedChannel" and "lastSelectedChannel" were set to "2" wasn't intuitive and some sample script code elsewhere in this section of the forum didn't include setting the values of "firstSelectedChannel" and "lastSelectedChannel" despite there being an implicit understanding that colour images might be involved.  :(

Bob.
TEC 140 'scope, FLI ML16803 camera, ASA DDM60 Pro mount.