Re: Cropping several parts of a set of images from multiple folders

Posted by otills on
URL: http://imagej.273.s1.nabble.com/Cropping-several-parts-of-a-set-of-images-from-multiple-folders-tp3689264p3689266.html

Hi Chris, thanks for this reply.

I've made some progress on this myself also.

The macro below allows me to create new stacks based on specified ROIs of images in subfolders within a specified folder (the ROI doesn't change within each subfolder (e.g. C3-D4 or C5-D6 in the macro below). I can therefore just copy and paste the macro whilst changing the "myFolder" variable). I've also included a labelling function to label each frame with; the frame number, which well of the multi-well plate I'm imaging (e.g. A or B.. myWell variable below), myPosition and myFolder.

I had a lot of trouble getting the images to save in the desired sub-folder, however it's all working now.. the problems were varied including slashes in the wrong direction and spaces where there shouldn't be any (first attempt at macro writing). I might try having a play with some of your macro as it seems somewhat more streamlined than mine!

myFolder="140210_1"

myPosition="C3-D4"

myWell="A"

run("Image Sequence...", "open=[/Volumes/Macintosh HD 2/140210_continued//"+ myFolder +"//"+ myPosition +"//img0000000.tif]] number=300 starting=1 increment=1 scale=100 file=[] or=[] sort");

makeRectangle(389, 221, 430, 430);

run("Duplicate...", "title=C3-1 duplicate range=1-300");

run("Label...", "starting=0 interval=1 x=5 y=20 font=25 text=A_"+ myPosition +"_"+ myFolder +"");

run("Image Sequence... ", "format=TIFF name="+ myFolder +"_"+ myPosition +"_A_ start=0 digits=4 save=//Users//Oli//Crop//HD2_Crop//"+ myFolder +"//"+ myPosition +"//"+ myFolder +"_"+ myPosition +"_A_ start=0 digits=4]");

run("Close");

myWell="B"

makeRectangle(1364, 227, 409, 409);

run("Duplicate...", "title=C3-1 duplicate range=1-300");

run("Label...", "starting=0 interval=1 x=5 y=20 font=25 text=B_"+ myPosition +"_"+ myFolder +"");

run("Image Sequence... ", "format=TIFF name="+ myFolder +"_"+ myPosition +"_B_ start=0 digits=4 save=//Users//Oli//Crop//HD2_Crop//"+ myFolder +"//"+ myPosition +"//"+ myFolder +"_"+ myPosition +"_B_ start=0 digits=4]");

run("Close");


//

myPosition="C5-D6"

myWell="A"

run("Image Sequence...", "open=[/Volumes/Macintosh HD 2/140210_continued//"+ myFolder +"//"+ myPosition +"//img0000000.tif]] number=300 starting=1 increment=1 scale=100 file=[] or=[] sort");

makeRectangle(362, 266, 403, 403);

run("Duplicate...", "title=C3-1 duplicate range=1-300");

run("Label...", "starting=0 interval=1 x=5 y=20 font=25 text=A_"+ myPosition +"_"+ myFolder +"");

run("Image Sequence... ", "format=TIFF name="+ myFolder +"_"+ myPosition +"_A_ start=0 digits=4 save=//Users//Oli//Crop//HD2_Crop//"+ myFolder +"//"+ myPosition +"//"+ myFolder +"_"+ myPosition +"_A_ start=0 digits=4]");

run("Close");

myWell="B"

makeRectangle(1308, 240, 537, 537);

run("Duplicate...", "title=C3-1 duplicate range=1-300");

run("Label...", "starting=0 interval=1 x=5 y=20 font=25 text=B_"+ myPosition +"_"+ myFolder +"");

run("Image Sequence... ", "format=TIFF name="+ myFolder +"_"+ myPosition +"_B_ start=0 digits=4 save=//Users//Oli//Crop//HD2_Crop//"+ myFolder +"//"+ myPosition +"//"+ myFolder +"_"+ myPosition +"_B_ start=0 digits=4]");

run("Close");

//


Cheers, Oli

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Ninja Chris
Sent: 22 February 2010 13:12
To: [hidden email]
Subject: Re: Cropping several parts of a set of images from multiple folders

Hi Oli,

I'm trying to automate the export of ROIs in a stack to new subfolders. I've
been adapting the BatchProcess Function too and have got this far:

sdir = getDirectory("choose source directory ");
n = roiManager("count");
for (i=0; i<n; i++) {
     roiManager("select", i);
     bee = "bee_"+i+"_";
     ddir = sdir+bee;
     File.makeDirectory(ddir);
     run("Duplicate...", "title = bee duplicate range=1-3000");
     run("Image Sequence... ", "format=TIFF name=["+bee+"] start=0 digits=4
save=["+ddir+"]");
close();
  }

If you open your stack, select a few ROIs and then run this macro it will
ask you what the parent folder is then generate a folder for each ROI
(they're called "bee" because I'm processing videos of bees). It will also
duplicate each ROI and save it as a separate stack. Unfortunately I can't
get it to save the relevant ROI stacks in the right folder so it just dumps
them in the parent at the moment. If I get it working properly I'll post
back.
Hope this helps,

Chris
--
View this message in context: http://n2.nabble.com/Cropping-several-parts-of-a-set-of-images-from-multiple-folders-tp4576230p4611905.html
Sent from the ImageJ mailing list archive at Nabble.com.