Easily strip alpha channel from images in Mathematica - wolfram-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"]

Related

How do you make a function for a n-pointed star? in mathematica

Im trying to make a function named star for an n-pointed star with radius 1, center (0,0) and start line is (0,1) with an angle n(((n-1)/n)*Pi). How??
My end goal is to make the star on the image I posted:
What mathematica functions do I use? graphics, Line, Table??
If possible id love an example :D.
I have not gotten far, the only code I have written is: star[n_] := Graphics[Table[Line[{}, {}], {}]];
Try
star[n_]:=Graphics[Line[Table[{Cos[t*(n-1)^2/n*Pi],Sin[t*(n-1)^2/n*Pi]},{t,0,n}]]];
star[5]
star[13]
Take it apart, look at what just the Table[...] gives you. And exactly why does that use {t,0,n} instead of {t,0,n-1}. And why does it have (n-1)^2/n in it, what does that do? Then look up the documentation for Line[...] and see what it accepts for input and how the output of Table[...] provides that.
Then the challenging part is that you have to reverse engineer my thought process to figure out what I was thinking and how I got to t*(n-1)^2/n*Pi. If you believe you understand all this then see if you can rewrite the calculations in a different way and still get the same result. And then can you find a way to make this much simpler and easier to understand exactly what it is doing and exactly why?

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!

Vuetify Input Mask

Has anyone found an Input Mask library that works with Vuetify using a directive? I have tried Cleave.js, vue-mask, imask, and a few other and they all seem to fall short or are buggy. Any suggestions would be appreciated.
is there a specific thing that you are trying to achieve, the mask that they have by default you can use to mask text fields already they have some pre-made and you can customize to your needs. I'm just curious as what you are trying to achieve.
Thanks for your response. I have looked at the provided masks but they dont work for my needs. For instance, I want to have an input field that only accepts numbers but isnt limited to the amount of numbers. If I put mask="####" as the attribute it will only allow numbers but only 4 digits. If I want to allow unlimited numbers how would I accomplish that? Thanks for your help

how do you specify an AlphaChannelType arguments to alpha() in ruby imagemagick (magick)

I'm trying to use the img.alpha(SOMETHING) command in the ruby magick library (in a custom manipulate routine used by carrierwave).
alpha() expects an argument of Magick::AlphaChannelType but I cannot find any doucmentaiton on how to specify such an argument, or what options are available.
The docs say the argument shoudl be:
One of the following values of the AlphaChannelType enumeration:
ActivateAlphaChannel Enable the images use of transparency. If
transparency data did not exist, allocate the data and set to opaque.
If the image previously had transparency data, the data is again
enable as it was when turned off. The transparency data is not changed
or modified in any way.
...
But do not give any examples of how to actually specify one of the 10 possible argument values.
The AlphaChannelTypes that alpha wants are constants within Magick so you want to use Magick::ActivateAlphaChannel, Magick::BackgroundAlphaChannel, ...:
img.alpha(Magick::ActivateAlphaChannel)
I don't my way around CarrierWave but I'd guess it just wants to see one of the Magick:: constants somewhere.

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

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.

Resources