Manipulate Image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Manipulate Image

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Manipulate Image

Post 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
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Manipulate Image

Post 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...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Manipulate Image

Post by fmw42 »

A shell script will allow you to program the changes using the IM command line commands
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Manipulate Image

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Manipulate Image

Post 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
rohitkrishna
Posts: 43
Joined: 2011-10-01T14:34:04-07:00
Authentication code: 8675308

Re: Manipulate Image

Post 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....
Post Reply