I am attempting to write a macro that takes a list of RGB values and files
names (from a prepared .txt file) and outputs small (e.g. 20 x 20 pixels) color image tiles. For example the external list file looks like this (filenames, followed by R, G, B values): Filename_1, 224, 155, 22 Filename_2, 33, 150, 20 Filename_3, 55, 200, 150 Etc. (the actual list is about 700 filenames long) I would like to run through this list and output little image squares (named with the filename) each with uniform colors matching the RGB specifications in the list. Recording the individual steps is easy, but referencing the external file and making this a batch process has me dead in the water. FWIW, I can format the external "lookup file" any way that works best. In case there is interest, my application deals with an attempt to chart choice of paper color (as represented by the RGB squares) used by an artist against other parameters including technique, subject matter and other more quantitative values. The artist is F. Holland Day, an American photographer. Many thanks in advance for any ideas to get me going on this project, Paul Paul Messier Conservation of Photographs & Works on Paper 617 782 7110 www.paulmessier.com -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Paul,
the following macro should do what you would like. Just edit the input and output paths in the first lines. Sincerely, Jerome input="/Users/jerome/Desktop/test.txt"; output="/Users/jerome/Desktop/"; s = split(File.openAsString(input),'\n'); for (i=0;i<s.length;i++) { line = split(s[i],','); newImage(line[0],"RGB Color",20,20,1); setForegroundColor(parseInt(line[1]), parseInt(line[2]), parseInt(line[3])); run("Select All"); run("Fill"); saveAs("Tiff", output+line[0]); close(); } On 22 May 2013 19:10, Paul Messier <[hidden email]> wrote: > I am attempting to write a macro that takes a list of RGB values and files > names (from a prepared .txt file) and outputs small (e.g. 20 x 20 pixels) > color image tiles. > > For example the external list file looks like this (filenames, followed by > R, G, B values): > > Filename_1, 224, 155, 22 > Filename_2, 33, 150, 20 > Filename_3, 55, 200, 150 > Etc. (the actual list is about 700 filenames long) > > I would like to run through this list and output little image squares (named > with the filename) each with uniform colors matching the RGB specifications > in the list. > > Recording the individual steps is easy, but referencing the external file > and making this a batch process has me dead in the water. FWIW, I can format > the external "lookup file" any way that works best. > > In case there is interest, my application deals with an attempt to chart > choice of paper color (as represented by the RGB squares) used by an artist > against other parameters including technique, subject matter and other more > quantitative values. The artist is F. Holland Day, an American photographer. > > > Many thanks in advance for any ideas to get me going on this project, > Paul > > Paul Messier > Conservation of Photographs & Works on Paper > 617 782 7110 > www.paulmessier.com > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Paul Messier
On May 22, 2013, at 1:10 PM, Paul Messier wrote:
> I am attempting to write a macro that takes a list of RGB values and files > names (from a prepared .txt file) and outputs small (e.g. 20 x 20 pixels) > color image tiles. > > For example the external list file looks like this (filenames, followed by > R, G, B values): > > Filename_1, 224, 155, 22 > Filename_2, 33, 150, 20 > Filename_3, 55, 200, 150 > Etc. (the actual list is about 700 filenames long) > > I would like to run through this list and output little image squares (named > with the filename) each with uniform colors matching the RGB specifications > in the list. > > Recording the individual steps is easy, but referencing the external file > and making this a batch process has me dead in the water. FWIW, I can format > the external "lookup file" any way that works best. > > In case there is interest, my application deals with an attempt to chart > choice of paper color (as represented by the RGB squares) used by an artist > against other parameters including technique, subject matter and other more > quantitative values. The artist is F. Holland Day, an American photographer. A macro something like this should do the job: lines = split(File.openAsString(""), "\n"); dir = getDirectory("Choose Output Directory"); setBatchMode(true); for (i=0; i<lines.length; i++) { items = split(lines[i], ","); name = items[0]; red = parseInt(items[1]); green = parseInt(items[2]); blue = parseInt(items[3]); newImage(name, "rgb", 20, 20, 1); setForegroundColor(red, green, blue); run("Select All"); run("Fill"); saveAs("tif", dir+name); close; } -wayne -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |