Module: RImageAnalysisTools
- Defined in:
- lib/rimageanalysistools/image/io/image_writer.rb,
lib/rimageanalysistools/drawing.rb,
lib/rimageanalysistools/centroids.rb,
lib/rimageanalysistools/get_image.rb,
lib/rimageanalysistools/get_filter.rb,
lib/rimageanalysistools/graythresh.rb,
lib/rimageanalysistools/skeletonizer.rb,
lib/rimageanalysistools/thread_queue.rb,
lib/rimageanalysistools/method/method.rb,
lib/rimageanalysistools/simple_output.rb,
lib/rimageanalysistools/create_parameters.rb,
lib/rimageanalysistools/image/io/url_image_reader.rb,
lib/rimageanalysistools/method/centromere_finding_method.rb
Overview
– /* ***** BEGIN LICENSE BLOCK *****
*
* Copyright (c) 2012 Colin J. Fuller
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* ***** END LICENSE BLOCK ***** */
++
Defined Under Namespace
Modules: Centroids Classes: CentromereFindingMethod, Drawing, ImageWriter, Method, Skeletonizer, ThreadQueue, URLImageReader
Constant Summary collapse
- Filter_package_name =
"edu.stanford.cfuller.imageanalysistools.filter."
- IM_OUTPUT_DIR =
"output_images"
- QUANT_OUTPUT_DIR =
"quantification"
Class Method Summary collapse
-
.create_parameter_dictionary(parameter_hash) ⇒ ParameterDictionary
Creates a ParameterDictionary from a hash of parameters.
- .get_filter(filter_name) ⇒ Object
- .get_image(filename) ⇒ Object
-
.graythresh(arr) ⇒ Numeric
Thresholds the values in an array according to Otsu’s method (Otsu, 1979, DOI: 10.1109/TSMC.1979.4310076).
- .handle_output(original_filename, output_image, quant) ⇒ Object
- .read_image_directory(dirname) ⇒ Object
Class Method Details
.create_parameter_dictionary(parameter_hash) ⇒ ParameterDictionary
Creates a ParameterDictionary from a hash of parameters.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rimageanalysistools/create_parameters.rb', line 73 def self.create_parameter_dictionary(parameter_hash) p = ParameterDictionary.emptyDictionary parameter_hash.each do |k,v| p[k]= v end p end |
.get_filter(filter_name) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rimageanalysistools/get_filter.rb', line 34 def self.get_filter(filter_name) java_import (Filter_package_name + filter_name.to_s) const_get(filter_name).new end |
.get_image(filename) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rimageanalysistools/get_image.rb', line 35 def self.get_image(filename) ir = nil if filename.is_a? URI then ir = URLImageReader.new else ir = ImageReader.new end ir.read(filename) end |
.graythresh(arr) ⇒ Numeric
Thresholds the values in an array according to Otsu’s method (Otsu, 1979, DOI: 10.1109/TSMC.1979.4310076).
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rimageanalysistools/graythresh.rb', line 35 def self.graythresh(arr) num_steps = 1000.0 min = arr.reduce(Float::MAX) { |a,e| e < a ? e : a } max = arr.reduce(-1.0*Float::MAX) { |a,e| e > a ? e : a } mean = arr.reduce(0.0) { |a,e| a + e } / arr.length sorted = arr.sort step_size = (max - min)/(num_steps) best_eta = 0.0 best_threshold_value = 0.0 counts_upto_k = 0 mu = 0 return min if step_size == 0 min.step(max, step_size) do |k| last_count_upto_k = counts_upto_k last_count_upto_k.upto(sorted.length-1) do |i| if sorted[i] > k then break end counts_upto_k += 1 mu += sorted[i]*1.0/sorted.length end omega = counts_upto_k*1.0 / sorted.length eta = omega*(1-omega) * ((mean - mu)/(1-omega) - mu/omega)**2 if eta > best_eta then best_eta = eta best_threshold_value = k end end best_threshold_value end |
.handle_output(original_filename, output_image, quant) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rimageanalysistools/simple_output.rb', line 36 def self.handle_output(original_filename, output_image, quant) fn_parts = File.split(original_filename) im_dir = File.(IM_OUTPUT_DIR, fn_parts[0]) quant_dir = File.(QUANT_OUTPUT_DIR, fn_parts[0]) Dir.mkdir(im_dir) unless Dir.exist?(im_dir) Dir.mkdir(quant_dir) unless Dir.exist?(quant_dir) mask_fn = fn_parts[1] + "_output.ome.tif" quant_fn = fn_parts[1] + "_quant.txt" unless quant.nil? then quant_str = LocalAnalysis.generateDataOutputString(quant, nil) File.open(File.(quant_fn, quant_dir), 'w') do |f| f.puts quant_str end end unless output_image.nil? then output_image.writeToFile(File.(mask_fn, im_dir)) end end |
.read_image_directory(dirname) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rimageanalysistools/get_image.rb', line 49 def self.read_image_directory(dirname) ir = ImageReader.new images = [] Dir.foreach(dirname) do |f| images << ir.read(File.(f, dirname)) end end |