Skip to content

Commit f86be9c

Browse files
committed
Create new templates
Added new sample Ruby scripts based off the examples in http://imagej.net/JRuby_Scripting
1 parent 00d6f9a commit f86be9c

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Convert a directory of LSM files to BioRad .PIC
2+
java_import "ij.IJ"
3+
java_import "ij.process.StackConverter"
4+
5+
input_directory = "/home/mark/lsm-examples/"
6+
output_directory = "/home/mark/lsm-examples/biorad/"
7+
8+
include_class 'util.BatchOpener'
9+
include_class 'Biorad_Writer'
10+
11+
# Check that the input directory exists:
12+
unless FileTest.directory? input_directory
13+
ij.IJ.error "Input directory '#{input_directory} was not found"
14+
exit(-1)
15+
end
16+
17+
# Create the output directory if it doesn't exist:
18+
unless FileTest.exist? output_directory
19+
Dir.mkdir output_directory
20+
end
21+
22+
# Biorad filenames have a standard format, which we generate with
23+
# this function. ('channel' should be 1-indexed):
24+
def make_biorad_filename(lsm_filename,channel)
25+
lsm_filename.gsub(/.lsm$/,sprintf("%02d.pic",channel))
26+
end
27+
28+
Dir.entries(input_directory).each do |e|
29+
# Skip anything that doesn't have a '.lsm' extension:
30+
next unless e =~ /\.lsm$/
31+
puts "Converting: #{e}"
32+
# Open the image file to an array of ImagePlus objects:
33+
a = BatchOpener.open("#{input_directory}#{e}")
34+
# Create the writer plugin object:
35+
writer = Biorad_Writer.new
36+
# Now, for each channel in the input image, write out
37+
index = 0
38+
a.each do |image|
39+
# The Biorad_Writer doesn't like COLOR_256 images, so convert to
40+
# GRAY8:
41+
ij.process.StackConverter.new(image).convertToGray8
42+
biorad_filename = make_biorad_filename e, index + 1
43+
puts " Writing: #{biorad_filename}"
44+
writer.save image, output_directory, biorad_filename
45+
index += 1
46+
image.close
47+
end
48+
end
49+
50+
ij.IJ.showMessage("Finished converting to Biorad format!")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @ImagePlus i
2+
# A basic script that inverts the current image.
3+
# NB: this requires that an image is already open.
4+
# The ImagePlus is populated automatically via the
5+
# scripting framework.
6+
# We explicitly import the java ij.ImagePlus class,
7+
# but this may not be necessary if you already have
8+
# an imagej.rb required into this script.
9+
java_import "ij.ImagePlus"
10+
11+
# Invert the image and redraw it
12+
$i.getProcessor.invert
13+
$i.updateAndDraw
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Manually create and display a color ImagePlus
2+
java_import "ij.process.ColorProcessor"
3+
java_import "ij.ImagePlus"
4+
5+
w = 800
6+
h = 600
7+
8+
# Create an ImagePlus
9+
cp = ColorProcessor.new(w, h)
10+
i = ij.ImagePlus.new "Plasma Cloud", cp
11+
12+
# Set Image's pixels
13+
pixels = cp.getPixels;
14+
java.util.Arrays.fill(pixels, 0, w*h/2 - 1, 0x0000FF00)
15+
16+
# Display the image
17+
i.show

0 commit comments

Comments
 (0)