SVG Filter Grayscale to Alpha - svg

I have an rgb image with various colors and grayish parts (white - grey - black).
Now I would like to transform the grayish pixels to transparent / alpha, whilst keeping the colored pixels as they are.
As of now I am rendering the image on a canvas and then iterate over the pixels. If the channels R, G, B are close for a pixel it turn the pixels alpha to 0.
Is there a way of doing this via svg filters?
https://www.w3.org/TR/SVG11/filters.html

Related

Is there a term for non-grayness of a color (where black and white would be non-gray)?

If the RGB space were rendered as a cube, white, black, red, green, blue, yellow, magenta, and cyan would be corners; gray would lie at the center of the cube.
Is there a name for colors on the surface of that cube?
In simple terms, non-grayness could be quantified (with r, g, and b from [0..1]) as
abs(max(r, g, b) - .5) / .5
Here, white, black, red, orange, etc. would have a "non-grayness" of 1.
A recent article in colour vision theory (an open-access version is available on bioRxiv) defined this concept as vividness.
It is based on the representation of colours in a colour solid, where each axis is one component of colour. In such solids, the origin is black and the opposite edge is white. For example, this is the colour solid of the CMYK colourspace, plotted in this StackOverflow question:
Vivid colours are colours on the surface of this colour solid, which is exactly what you are describing in your question:
We define a measure of colour vividness, such that points on the surface are maximally vivid and the ‘grey’ centre is minimally vivid.

Libgdx Fill in Color of Image start from the center like an animation

I would like to preform a color fill in from the center of the image in Libgdx. I know I have to use 2 different texture to perform the color change with setColor on the current image to the next image color, but how can I fill in the color starting from the center of the image just like performing an animation?

Getting the coordinates of the "text" bounding box of a grayscaled picture by using command line in linux

Just what the title says .
Strictly speaking what I define as "text" bounding box for a grayscaled image is a set of 4 coordinates (x,y,x+width,y+height) that have to define a rectangle area in that image that has the maximum number of non white pixels and at the same time the least possible number of white pixels(without chagning the maximum amount of non-white pixel). I have text in quotation marks since images does not actually contain text because images do only contain pixels with colours.
Having installed ImageMagick in my Ubuntu and typing in the terminal the command: $convert input.png -trim ouput.png , I get :
Open the two images in new tabs in your web browser and you will understand the difference they have and you will also understand what I define as "text" bounding box.
The output.png has actually the width and height that I am looking for.I do not know how to get x and y coordinates.
The answer provided here (1) for pdf pages does not meet my criteria since the "text" bounding box that gs gives me has big white margins ( and actually as far as I can understand what gs defines as "text" bounding box for a pdf is something different from my definition of "text" bounding box for a picture).
I don't understand all the words in your description, and I think a diagram would help, but if you just want to know what -trim would do as your sample code implies:
identify -format "%#" image.png
200x100+10+20
So, for your image, you get
identify -format "%#" paper.png
406x620+38+68
which means that your box is 38 pixels to the right of the top left corner and 68 pixels down from the top left corner, and it is 406 pixels wide and 620 pixels tall.
And if I draw in that rectangle in red, I get:
convert paper.png -stroke red -fill none -draw "rectangle 38,68 444,688" result.png
An alternative way of getting the same result but using convert in place of identify is:
convert -format %# paper.png info:
406x620+38+68
Images don't have a 'text bounding box', because obviously there is no text.
The images in the PDF file may themselves contain white pixels, if they are scanned from books then they almost certainly will. These pixels count towards the bounding box of the image, because they are white not transparent and will obscure anything drawn beneath them.
Its also rather nonsensical to define a 'text bounding box' as 'an area in that picture that has no white margins and only text'. If its in an image then there is no text, only image samples which define pixels. That's a picture of text, not actually text. In order to differentiate between areas of an image containing text and areas containing non-text you will need OCR software, nothing else is going to do this because only OCR software is capable of detecting the difference between text and non-text.

Tinting Drawn Textures with the Color property in XNA / Monogame, how to balance?

I have these four icons that look like this:
But I want to be able to just have 1 gray icon and then tint them different colors by setting the color in XNA / Monogames Draw function.
I took one of the images and pulled all the colour out and made it a bit lighter it to get
I also tried a version where the center of the gray image is fully white but neither look right in the game, here's an image with the icons on top and my tinted gray on the bottom (the tint color is sampled from the center of the original icons):
I figure there should be a way, given the original icons, to figure out how to make the gray icon and also the colors to plug into the draw function so that I get an exact copy of the original. I assume this is possible? How do you do it?
EDIT:
To elaborate on my issue here is another image all with blue icons, the top images are all the original blue icon for comparison. The bottom images are all grey icons I used to tint to make the middle icons. The grey icons are, from left to right, 0 saturation, 0 saturation and 100 brightness, and auto level + 0 saturation. It seems to me that by setting the saturation to 0 I am losing the ability to make the icon look right as it's not just "darker" blue but also "bluer" blue.
EDIT 2: I don't think it's possible, thanks for the help Goose.
Would it work if the grey icon was full white at the center (it's brightest point) and got darker from there.
Then you could just sample the color at the center of your source image (the colored ones) and tint with that.
I think the issue you are seeing now is that the grey image will darken the color you are tinting with, so you actually want to tint with the source color PLUS the amount of grey at the brightest point in the image (if that makes sense).

Convert a black & white image to white & transparent

I have a black and white System.Drawing.Bitmap being passed from a 3rd party SDK, that I want to convert from black on white to white on transparent... i.e. make all the black pixels white, and all the white pixels transparent.
Do I have to iterate over every pixel, check the color and change it accordingly? How do I go about this?
If it's a paletted image (as it should be, given that it's a BW image) you could replace black with transparent inside the palette of the bitmap (Palette property of Bitmap, edit its Entries property).

Resources