Ruby - How to open a picture pixels in a 2D matrix - ruby

I'm using Ruby 1.9.
I would like to know what gem would you use to open a picture in a 2D matrix?
I want to be able to read and modify each pixel individually.
Thanks.

RMagick. Specifically you want the Image#pixel_color method.
There is also an each_pixel method to iterate through for reading.

If you need it only for operations that will not be massive:
https://github.com/wvanbergen/chunky_png
If you don't want to use imagemagick but need speed boost (ruby library with C inlines):
https://github.com/wvanbergen/oily_png

ChunkyPNG is also a pretty good library if you want to work with PNGs.

Related

2D distributions in the HistFactory?

How can I specify in the construction of the HistFactory the signal and background to be 2-dimensional distributions?
I have understood than in RooStats you need to change the TH1 to a TH2.
At the moment to write my model in the json file can I use a ndarray to do something similar?.
Which is the correct way to do this?
I hope someone can help me and thank you in advance.
Currently the best way is to unroll the distributions e.g.
{'data': 2darray.ravel().tolist()}
Since mathematically it doesn't make any difference.
If you want to convert from XML+ROOT this is not yet supported (but could be). If so, please open an issue on GitHub.
Thanks for using pyhf!

How to use PNG mask in segmentation object detection with Tensorflow

I am using tutorial from here.
I use mask_rcnn_inception_v2 detection model with my own dataset. I want to add PNG mask, i use some applications to do it. but I wonder how i put this data to be used in detection. I see the mention anywhere.
How to implement the PNG mask in object detection ? (where i put it, how to use it)
Do you know how to launch the evaluation and training in same time on tensorboard i see it is possible.
generally where i can ask all Tensorflow general question as configuration file explanations
On Github Tensorflow it is specified we have to ask question here because not a Tensorflow issue and great community here with some great guys!
thanks to guy on github he points a missing configuration in pipeline.config
number_of_stages: 3
and it changes all the result i can see the mask now. youpi !
For any further information, there's a good explanation here:
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/instance_segmentation.md
It explains how to prepare you masks and what to modify.

Easily strip alpha channel from images in Mathematica

What is the simplest way to strip the alpha channel (and possible convert images to greyscale) in Mathematica?
I would like to use ImageAssemble, but some of the images come with and some without an alpha channel. Is there a simpler built-in way than manipulating the ImageData directly?
The RemoveAlphaChannel function will do this.
For Mathematica 7, I believe this works:
ColorCombine#Most#ColorSeparate## &
It's not robust at this point, but type checking could be added.
Your second question (not sure it is) conversion to grayscale, is done with:
ColorConvert[image, "Grayscale"]

How to create a spreadsheet with formulas using Rails?

I need some gem/plugin to create an Excel spreadsheet with formulas to use in my Rails application. Any suggestions?
I've used Roo and it's quite good and easy to do spreadsheet processing (once you get all the gem dependencies installed). However, it doesn't support formulas natively. It won't eval the formula and return the result (this would be difficult I think -- use the excel engine?) but it will give you the text of the formula, for example:
=SUM(.A1,.B1)
It'd be pretty easy to handle this specific case but if you have many different formulas and functions then rolling your own evaluator is going to be difficult. Going and getting A1 and B1 to add them together is very doable with Roo. It's just a question of how complex your formulas are.
writeexcel does it wonderfully!
I think you should create blank Excel file with formulas and then fill it with Rails. Because you can't create formulas with Ruby.
There's a spreadsheet gem listed on RubyGems but having never used it I can't recommend it.

how do i create charts from a cvs file using ruby

csv sample:
Date,128,440,1024,Mixed
6/30/2010,342,-0.26%,-0.91%,1.51%,-0.97%
6/24/2010,0.23%,0.50%,-1.34%,0.67%
i want to render this data in a multi-line graph
Well, you first need to parse the CSV. I suggest FasterCSV - the RDoc explains pretty much everything you need to know.
You'll need to have ImageMagick and RMagick installed, then you can use Gruff. Or if you've got an Internet connection on the machine you are running the script on, you can use Google Charts with this Ruby plugin. Or if you want to get back SVG, consider Scruffy.
The page about Gruff has a code sample showing how to create a multi-line graph. Basically, you need to collect together all the data you want in each line into an array. Looks basically like the primary thing you need to do is array mangling.

Resources