How to create semi-transparent image using imagemagick - png

I have a hex (i.e. #FF0000) color and want to generate 50% transparent 50x50 image using imagemagick from command line.

I had to figure out something similar when I was working with CSS 3 and RGBA.
convert -size 50x50 xc:'rgba(255,0,0,0.5)' red_0.5_pixel.png

Related

Resize image and create 3x3 tiles with ImageMagick

I managed to make tiles with ImageMagick like this:
-size 900x900 tile:D:\tile.jpg D:\tiles.jpg
But i want to resize the image before the tiling (300*300px) - and then maybe afterwards apply a sharpen, but the most important is the resizing.
How do i do that in one command line?
Work from a simple command like this...
convert D:\tile.jpg -resize 300x300 -write mpr:tiler +delete ^
-size 900x900 tile:mpr:tiler -sharpen 0x2 D:\tiles.jpg
That starts by reading in your "tile.jpg" image and resizes it to 300x300. Then it writes that resized image to an ImageMagick built-in memory register named "mpr:tiler" and deletes it from the current list. (You can name it "mpr:almost_anything".)
Next the command sets a canvas size of 900x900 and creates a tiled canvas filled with that "mpr:tiler" image.
You can add sharpening and other operations after reading in the input image and before writing it to the memory register, or after creating the tiled image and before writing it to an output file.
The command above is in Windows syntax. To run it in *nix change that continued-line caret "^" to a backslash "\". If you're using ImageMagick v7 replace "convert" with "magick".

Add a pattern repeated image as a background of another image using ImageMagick convert

I want to add a pattern repeated image as the background of another image that has spaces around. For example i have the pattern 200x200 and an image 1200x800. I have accomplished to add a background color.
The command i'm using to add a background color
convert -background "#333" -resize 768x450 -gravity Center -extent 768x450
Now i need to add a pattern instead of that color. Some suggest that i should make the pattern as one image with the maximum size then use it to add it as background image.
Is it possible to do it with convert or any other command using ImageMagick ?
Not sure what you mean, but I am guessing it's this. Let's make a 200x200 tile to start off with:
convert -size 200x200 radial-gradient:red-blue t200x200.png
And now you want to make a 1200x800 image by tiling that basic unit:
convert -size 1200x800 tile:t200x200.png BigBoy.png
If you now want to overlay a fine-art, high-quality, centred portrait over the top of your harmonious, subtle background, you can do this:
convert -size 1200x800 tile:t200x200.png -gravity center smiley.gif -composite BigBoy.png

Dividing Ground-penetrating radar profile through image processing

Please look at the attached image. It is a GPR profile and using image processing techniques, I am trying to divide this image into 3 zones by labeling with colors the whole image on the top:
when parabolas in the image are very clear and distinct with high pixel values - green zone/ line at the top
when parabolas in the image are blurred but visible - yellow zone
when parabolas are distorted or when not parabolas are present - red zone
What techniques should I use? What's the best approach to solve it?
I have tried various techniques but not with success in every case, because, as you can in the following image, sometimes the parabolas are too close to one another and identifying them is becoming an issue.
A sample of how I want to zone it: https://www.dropbox.com/s/9zm9epgf0gt7591/sample.png?dl=0
One of the tried code: simplest one.
clear all
clc
%read png image
H=imread ('origpng.png');
%convert to gray scale
I = rgb2gray(H);
I(I>150)=0;I(I<100)=0;
figure,imshow(I)
J=I;
J=255-J;
figure, imshow (J)
J(J<255)=0;
figure,imshow (J)
Your question is not very clearly posed, but I spent some time on it and felt like sharing my thoughts. I am not preteding for an instant that this is anywhere near a complete, or rigorous answer - just some musings that might give you some ideas. Also, I use ImageMagick, but if you have and know Matlab, you should use that - I am not suggesting you switch tools.
First, I did a Canny Edge detection like this:
convert http://i.stack.imgur.com/XITAE.png -canny 0x1+15%+50% canny.jpg
that gives me this:
I then "squash" that down till it is just 1 pixel high, which effectively totals up and averages all the columns - I make it 10 pixels high here so you can see it. Where it is white, there are lots of parabolas, elsewhere there are fewer.
Then I stretch that back up to the full height of the original image and blur it a bit - note that everything up to the following image is just one line of "code":
convert http://i.stack.imgur.com/XITAE.png -canny 0x1+15%+50% -resize x1! -normalize -resize 827x310! -blur 0x11 -colorspace gray mask.png
I then use the above as an opacity mask for a red image the same size as your original like this:
convert -size 827x310! xc:red mask.png -compose copy-opacity -composite colouredmask.png
Then I took your original image and coloured it with yellow like this by first creating a yellow image and then blending it onto your image and then I blended the red image from above on top of that:
convert -size 827x310! xc:yellow yellow.png
convert http://i.stack.imgur.com/XITAE.png yellow.png -compose colorize -composite colouredmask.png -compose overlay -composite result.png
giving
Obviously you can set different parameters and use different thresholds and things, but it kind of heads towards the sort of thing you are aiming it.
So the entire process is:
# Make mask of peaky areas - line 1
convert http://i.stack.imgur.com/XITAE.png -canny 0x1+15%+50% -resize x1! -normalize -resize 827x310! -blur 0x11 -colorspace gray mask.png
# Colour mask with red - line 2
convert -size 827x310! xc:red mask.png -compose copy-opacity -composite colouredmask.png
# Tint original image with yellow and then overlay semi-transparent red area
convert -size 827x310! xc:yellow yellow.png
convert http://i.stack.imgur.com/XITAE.png yellow.png -compose colorize -composite colouredmask.png -compose overlay -composite result.png
Notes
Squashing pixels... sorry for confusing you with my terminology! Basically, when I squash the pixels down to a single row, you need to imagine dropping a brick on the top of the image and flattening it down to just one pixel tall. So, essentially, you draw an imaginary line underneath the image and then you work across the image totalling up the number of WHITE (i.e. edge) pixels in each vertical column. Columns that have more white pixels will add up to larger numbers. Columns that have no white pixels will add up to zero. Once you have got the totals for each column, you find the highest total - let's say it is 32 and then you multiply all totals by 255/32 so that everything is normalized to 255, or white. Now the squashed strip represents the edge energy in each column. And I then use that as the opacity for the red when I overlay - so columns with more white edges in the Canny image will show up with more red in the result.
Let's demo what happens if I squash down to 10 pixels wide and 1 pixel high before scaling back up to the original size - basically it means that my resulting mask will have only 10 possible values (or columns) columns and that each column will be a single constant brightness. I'll put the Canny image underneath so you can see that the brightness of the squashed strip represents the edge energy:
convert http://i.stack.imgur.com/XITAE.png -canny 0x1+15%+50% -resize 10x1! -normalize -scale 827x310! mask.png
If you want to introduce another colour, you need to work out what your algorithm is for controlling where that colour should appear. You then do exactly the same thing again - you make a mask that is light where you want that colour in your output image and dark where you don't want that colour. Then you use that mask as the opacity for your new colour (as I did at the line labelled line 2 above) and then you overlay it like I did in the last line of my code above.

Image Magick: convert and composite in one command

I am currently working on a automation script to convert imgaes for use on websites. Every image gets a white and black border and is combined with a prepared alpha channel image. The black border (outer border) combined with the alpha channel will look like a shadow when everything is done.
I've got the following files:
test.jpg (the test image)
test.tga (the alpha channel)
And I convert the input image in 2 steps:
convert test.jpg -bordercolor #FFFFFF -border 15 -bordercolor #000000 -border 30 test.png
(adds the white and black border to the image and saves as 'test.png')
composite -compose CopyOpacity test.tga test.png test2.png
(joins image file with alpha channel from test.tga and saves as test2.png)
So now my question is: Is there any way to invoke both steps as one command? I know that convert also supports the -compose options, if I got that right from the manual, but I could not get it working. It would be best, if I could edit and join the image with the alpha channel with one command. (Command will be executed from my Application and I don't want to execute many sub-processes)
Maybe someone knows a solution for this.
Thanks in advance!

How to change background color of an eps file while converting it to jpeg or png

I am converting eps (Encapsulated PostScript) files to jpeg files with ghostscript. A sample command I use is:
gswin32.exe -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r600x600 -dGraphicsAlphaBits=4 -dUseCIEColor -dEPSCrop -sOutputFile=”a.jpeg” b.eps
The input eps files come with white backgrounds (I only have their clipping path). What I need to do is change this white background to another color in the output images, or it would be even better if I could make them transparent (output file format would be png). How can I do this?
never tried it myself but you should be able to convert your eps file into png by setting:
-sDEVICE=pngalpha
also the pngalpha device has a -dBackgroundColor option:
-dBackgroundColor=16#RRGGBB (RGB color, default white = 16#ffffff) For
the pngalpha device only, set the
suggested background color in the PNG
bKGD chunk. When a program reading a
PNG file does not support alpha
transparency, the PNG library converts
the image using either a background
color if supplied by the program or
the bKGD chunk. One common web browser
has this problem, so when using on a web page you
would need to use
-dBackgroundColor=16#CCCC00 when creating alpha transparent PNG images
for use on the page.
more details here: Details of Ghostscript output devices see section 3.1. PNG file format
After you've obtained your (white background) images from Ghostscript, you could use ImageMagick's convert or GraphicMagick's gm convert commands to change the white to transparent background:
convert -background transparent my.png my_transp.png