I have the below css code for a web gradient on my page, I would like to make a background image that is exact to this gradient using the Gimp. Anyone have expertise doing this that might be able to lend some advice? Thanks
background-image:-webkit-linear-gradient(90deg, rgba(51, 51, 51, 1.00) 0.0% , rgba(26, 26, 26, 1.00) 50.5% , rgba(51, 51, 51, 1.00) 50.7% , rgba(77, 77, 77, 1.00) 100.0% );
GIMP can't parse that directly, althoug GIMP 2.8 ships with a Python script that can output gradients in this CSS syntax
You could make a python-script to parse CSS gradient syntax into GIMP Gradients,
and them use this gradient on an image.
Of course it is overkill if you are needing that just once -
I'd recommend creating a new gradient in GIMP, and manually edit the recorded file
(in ~/.gimp-2.8/gradients folder if you are on *nix, else check for the user gradients folder in the preferences).
GIMP's gradient file is straightforward - a text only file that goes like:
GIMP Gradient
Name: Untitled
2
0.000000 0.243464 0.486928 0.000000 0.000000 0.000000 1.000000 0.000000 1.000000 0.000000 1.000000 0 0 0 0
0.486928 0.743464 1.000000 0.000000 0.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 0 0 0 0
So this is a single gradient, with two segments - each line has the start-point, endpoint of each segment, the starting ARGB color, ending ARGB color, and ,...don't care, just keep the four zeros at the end: most likely they are used to describe the type of color in each endpoint, and we want 0.
Those rgba colors correspond to the following html-notations :
rgba(51, 51, 51, 1.00) - #333333 (Color A)
rgba(26, 26, 26, 1.00) - #1a1a1a (Color B)
rgba(51, 51, 51, 1.00) - #333333 (Color A)
rgba(77, 77, 77, 1.00) - #4d4d4d (Color C)
You could try creating a rectangular image (with height twice the width). Fill the top square half with a gradient of color A to color B, and the bottom square with a gradient from color A to color C.
Then you set it as your background image with "repeat" property enabled.
Related
I am trying to make some colors of the image transparent. Below are the images that I have.
Lets say that I want to remove the bold red color from the image and have it transparent. I am viewing my image as PDF, therefore the transparent color would be if the background would match with the pink on the side. I am using the code from Apple documentation which I slightly modified in the following way:
// inside 3rd loop
let hue = getHue(red: red, green: green, blue: blue)
let wantedHue = getHue(red: myPixel.redComponent, green: myPixel.greenComponent, blue: myPixel.blueComponent)
let isHueInRange = hue >= wantedHue - 0.1 && hue <= wantedHue + 0.1
let alpha:CGFloat = isHueInRange ? 0 : 1
Here is the result I get. As you can see, there is some color left and the background is not fully transparent. I made these modifications, because I need to be able to dynamically remove the background color of the image (my images won't have any humans or other complex objects in it. It will most likely be text and some rectangles. No color mixing. Just still colors.)
So what I do is finding the first pixel of the image and get its color. When I have the color I get its hue, but I manually set allowed range to be 0.2. I am assuming that the image won't contain any similar color to the one I have.
EDIT:
The original color is: rgb(200, 39, 39) - hsv(200, 80.5, 78.4)
The residue color is: rgb(246, 215, 210) - hsv(352, 14.6, 96.5)
The image I have:
The image I get after applying the filter:
To remove red colour, if the hue is between 0.9 and 0.1 (approximately) alpha should be zero.
Use the following and it will work.
let hue = getHue(red: red, green: green, blue: blue)
var alpha : CGFloat = 1.0
if (hue < 0.1 && hue >= 0.0) || (hue > 0.9 && hue <= 1.0){
alpha = 0.0
}
I think the problem with your code is it never consider the range 0.9 to 1.0. It always consider some range from 0.0xxx to 0.1xxxx.
Right now I am doing a parameter sweep and I am trying to convert my data to a 3D graph to show the results in a very nice fashion. The problem is that I don't quite know how to plot it as I am having an issue with the result variable.
mute_rate = [0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625]
mute_step = linspace(-2.5, 2.5, 6)
results = [949.58, 293.53, 57.69, 53.65, 293.41, 1257.49;
279.19, 97.94, 32.60, 29.52, 90.52, 286.94;
32.96, 28.06, 19.56, 6.44, 13.47, 55.80;
2.01, 1.52, 5.38, 1.00, 0.89, 1.41;
0.61, 0.01, 18.59, 0.03, 0.56, 1.22;
1.85, 1.51, 18.64, 18.57, 18.54, 6.90]
So the first row in the result variable presents the results of the mute rate and mute step performed on the population from my genetic algorithm. For example:
0.5, -2.5 = 949.58,
0.5, -1.5 = 293.53,
0.5, -0.5 = 57.69
etc
It sounds like you want something akin to:
mesh(mute_step, mute_rate, results);
shading interp;
Other styles of plot would be surf or pcolor (for a 2d view).
I have a code for brightness, and im currently looking into measuring contrast
from PIL import Image
from math import sqrt
imag = Image.open("../Images/noise.jpg")
imag = imag.convert ('RGB')
imag.show()
X,Y = 0,0
pixelRGB = imag.getpixel((X,Y))
R,G,B = pixelRGB
brightness = sum([R,G,B])/3 ##0 is dark (black) and 255 is bright (white)
print(brightness)
print(R,G,B)
Surely contrast could be something similiar to this code, any ideas would be great, thanks
Different folks have different ideas of contrast... one method is to look at the difference between the brightest and darkest pixel in the image, another is to look at the standard deviation of the pixels away from the mean. There are other statistics too. Note that it requires looking at all the pixels in the image - not just the first.
The simplest way to look at the statistics of an image is to use PIL's ImageStat function:
#!/usr/bin/env python3
from PIL import Image, ImageStat
# Load image
im = Image.open('image.png')
# Calculate statistics
stats = ImageStat.Stat(im)
for band,name in enumerate(im.getbands()):
print(f'Band: {name}, min/max: {stats.extrema[band]}, stddev: {stats.stddev[band]}')
So, if I create a greyscale image like this with ImageMagick:
magick -size 1024x768 gradient:"rgb(64,64,64)-rgb(200,200,200)" -depth 8 image.png
and run the above code, I get:
Band: L, min/max: (64, 200), stddev: 39.31443755161709
If I create a magenta-black gradient:
magick -size 1024x768 gradient:magenta-black -depth 8 image.png
and run the code, I get:
Band: R, min/max: (0, 255), stddev: 73.68457550034924
Band: G, min/max: (0, 0), stddev: 0.0
Band: B, min/max: (0, 255), stddev: 73.68457550034924
If the min and max are close, the contrast is low. If the min and max are widely spaced, the contrast is high. Likewise the standard deviation, as it measures how "spread out" the pixels are across the histogram.
I am using MATLAB 2015. I want to reduce the image color count. An RGB image will be segmentated using k-means algorithm. Then mean colors will be replaced with the colors I have.
The colors are (10),
black - [255, 255, 255],
yellow - [255, 255, 0],
orange - [255, 128, 0],
white - [255, 255, 255],
pink - [255, 153, 255],
lavender - [120, 102, 255],
brown - [153, 51, 0],
green - [0, 255, 0],
blue - [0, 0, 255],
red - [255, 0, 0].
I have succeeded clustering the image. Clustered images should be replaced with the nearest color. How can I change those colors after clustering?
In case you don't succeed in finding a way with MATLAB, you can remap the colours in an image at the command line with ImageMagick which is installed on most Linux distros and is available for OSX and Windows too.
First, you would make a swatch of the colours in your palette. You only need do this once obviously:
convert xc:black xc:yellow xc:"rgb(255,128,0)" \
xc:white xc:"rgb(255,153,255)" xc:"rgb(120,102,255)" \
xc:"rgb(153,51,0)" xc:lime xc:blue xc:red \
+append colormap.png
That looks like this (enlarged):
Now, let's assume you have an image like this colorwheel (colorwheel.png):
and you want to apply your palette (i.e. remap the colours to those in your swatch):
convert colorwheel.png +dither -remap colormap.png result.png
I have a very simple script that plots some random stuff and puts a textbox with background color. I am attempting to change the transparency of the background so that the plot shows through.
I have the following code:
x = rand(10);
plot(sin(x))
a = annotation('textbox', [0.5 0.5 0.1 0.1], 'String', 'Some Random Text');
set(a, 'BackgroundColor', [.7 .9 .7]);
set(a, 'FaceAlpha', 0.5);
And it results in an image like this:
So obviously the transparency has worked because part of the background colour is transparent.
Why is all of it not transparent? Have I done something wrong here?
Update: Mathworks confirmed that it probably is a bug which might be fixed in 2014b (to be released in July 2014). A temporary workaround is:
plot(sin(rand(10)))
a = annotation('textbox', [0.5 0.5 0.1 0.1], 'String', 'Some Random Text');
b = annotation('textbox', get(a,'Position'));
set(b, 'BackgroundColor', [0 0.5 0]);
set(b, 'FaceAlpha', 1);
uistack(a,'top')
One annotation for the text and below another for the background color.
It might be a Matlab bug actually. The documentation about annotations says:
FaceAlpha
Scalar alpha value in range [0 1] Transparency of object background.
Defines the degree to which the object's background color is
transparent. A value of 1 (the default) makes the background opaque, a
value of 0 makes the background completely transparent (that is,
invisible). The default value is 1.
I would conclude that the whole background should be affected but I can confirm that this is not the case also here (Matlab 2012b). I might file a bug report with them.
For a temporary fix, set the backgroundcolor as bright as possible ([0.9, 0.9, 0.9] for example) then one doesn't see the effect immediately.