Login  Register

Re: problem with Merge Channels and renaming

Posted by gnelson on Jun 07, 2017; 9:10am
URL: http://imagej.273.s1.nabble.com/problem-with-Merge-Channels-and-renaming-tp5018849p5018853.html

Hi Michael,

Matt is correct: if you insert:

selectWindow("RGB");

after the run merge channels line it will work.

I usually add this line before running image processing if I have other windows open just to ensure I am working with the correct image.  As to why it isn't choosing the last processed window, I don't know!  I think you can give a title to the merged image within the Merge Channels command, but I can't remember how to do this.  

Alternatively, you could remove the Duplicate command and add a line to rename the image to temp:
-------
macro "Proper Eq of RGB per channel" {
  //original = getImageID;
  title = getTitle;
  rename("temp");
//  run("Duplicate...", "title=temp");
  run("Split Channels");
  selectWindow("temp (blue)");
  run("Enhance Contrast...", "saturated=0 equalize");
  selectWindow("temp (green)");
  run("Enhance Contrast...", "saturated=0 equalize");
  selectWindow("temp (red)");
  run("Enhance Contrast...", "saturated=0 equalize");
  run("Merge Channels...", "c1=[temp (red)] c2=[temp (green)] c3=[temp (blue)]");

// selectWindow("RGB");
  rename("EQ_" + title);
}
-----
Then there is only one image open so this is the active window.

As an aside, out of sheer curiosity, I thought it would be less computer intensive to convert the RGB to a stack and then select the channels rather than creating separate images, like so:

macro "Proper Eq of RGB per channel" {
  //original = getImageID;
  title = getTitle;
  run("RGB Stack");
  Stack.setSlice(1);
  run("Enhance Contrast", "saturated=0 equalize");
  Stack.setSlice(2);
  run("Enhance Contrast", "saturated=0 equalize");
  Stack.setSlice(3);
  run("Enhance Contrast", "saturated=0 equalize");
  run("RGB Color");
  rename("EQ_" + title);
}

But this gives a different result!  And it is different to the result obtained if you just open the rgb and run the enhanced contrast on that.  I have no idea why.

Glyn.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html