Page 1 of 1
Manipulate Image
Posted: 2011-11-18T18:05:54-07:00
by rohitkrishna
Hi every one again..
I have a doubt which is smthing lik this.... i have a one-dimension array which contain r,g,b values in differnet offsets of an image and based on some calculations i make some changes to the pixels...i want to reflect these changes in image by changing the pixels in original image with the new values which i get after calculations.
Can anyone please tell me how to do this in image magick ?
Thanks in advance.
Re: Manipulate Image
Posted: 2011-11-21T15:20:38-07:00
by fmw42
I presume you have a 1D image of RGB values in some standard format such as gif or tiff or png, etc. And you want to replace some pixels with different colors at specific locations. There are several approaches. The easiest or most efficient may be to just draw those colored pixels at the locations you want
see
http://www.imagemagick.org/Usage/draw/#primitives
Re: Manipulate Image
Posted: 2011-11-21T22:14:33-07:00
by rohitkrishna
fmw42 wrote:I presume you have a 1D image of RGB values in some standard format such as gif or tiff or png, etc. And you want to replace some pixels with different colors at specific locations. There are several approaches. The easiest or most efficient may be to just draw those colored pixels at the locations you want
see
http://www.imagemagick.org/Usage/draw/#primitives
Thanks for reply..but i want it in programmatical way...not command arguments...
Re: Manipulate Image
Posted: 2011-11-22T09:48:47-07:00
by fmw42
A shell script will allow you to program the changes using the IM command line commands
Re: Manipulate Image
Posted: 2011-11-22T10:14:22-07:00
by rohitkrishna
fmw42 wrote:A shell script will allow you to program the changes using the IM command line commands
Thankyou..can u provide an example please..iam novoice in shell scripting.
Re: Manipulate Image
Posted: 2011-11-22T14:16:24-07:00
by fmw42
Here is a simple unix bash script that will create a 1D horizontal gradient and put 3 different rgb colors at different locations as specified from a text file.
Save the following as a file called whatever you want. I used test_changecolor
Code: Select all
#!/bin/bash
# define file of colors and positions
infile="testfile.txt"
# create 1D gradient as test image
convert -size 1x256 gradient: -rotate 90 grad1x256.png
# set up string for -draw from colors and positions
string=""
while read color position; do
string="$string fill $color point $position"
done < $infile
# color gradient from colors and positions in infile
convert grad1x256.png -draw "$string" grad1x256_colors.png
exit 0
Here is the infile=textfile.txt that contains the 3 colors and positions to place them. Note that there is no return or new line after the last color position.
Code: Select all
rgb(255,0,0) 25,0
rgb(0,255,0) 50,0
rgb(0,0,255) 100,0
See
http://www.imagemagick.org/Usage/draw/
http://www.imagemagick.org/Usage/draw/#primitives
http://www.imagemagick.org/Usage/draw/#mvg
http://www.imagemagick.org/script/magic ... aphics.php
Re: Manipulate Image
Posted: 2011-11-22T14:31:59-07:00
by rohitkrishna
fmw42 wrote:Here is a simple unix bash script that will create a 1D horizontal gradient and put 3 different rgb colors at different locations as specified from a text file.
Save the following as a file called whatever you want. I used test_changecolor
Code: Select all
#!/bin/bash
# define file of colors and positions
infile="testfile.txt"
# create 1D gradient as test image
convert -size 1x256 gradient: -rotate 90 grad1x256.png
# set up string for -draw from colors and positions
string=""
while read color position; do
string="$string fill $color point $position"
done < $infile
# color gradient from colors and positions in infile
convert grad1x256.png -draw "$string" grad1x256_colors.png
exit 0
Here is the infile=textfile.txt that contains the 3 colors and positions to place them. Note that there is no return or new line after the last color position.
Code: Select all
rgb(255,0,0) 25,0
rgb(0,255,0) 50,0
rgb(0,0,255) 100,0
See
http://www.imagemagick.org/Usage/draw/
http://www.imagemagick.org/Usage/draw/#primitives
http://www.imagemagick.org/Usage/draw/#mvg
http://www.imagemagick.org/script/magic ... aphics.php
Thankq very much....