flipping every other line of pixel in an image
flipping every other line of pixel in an image
Hi,
I'm new to ImageMagick, I was wondering is it possible to use IM to flip a line of pixel horizontal at every other line in an image.
I have an image that has a gradient from black to white. The first line of pixel is black to white gradient, from left to right. The second line of pixel is a gradient of white to black, from left to right again. The third is a repeat of first line, the fourth line is a repeat of the second line and so on so forth. I want to flip every other(even) line so the gradient goes from black to white gradient, from left to right. Any help will be greatly appreciated, thanks.
Hang
I'm new to ImageMagick, I was wondering is it possible to use IM to flip a line of pixel horizontal at every other line in an image.
I have an image that has a gradient from black to white. The first line of pixel is black to white gradient, from left to right. The second line of pixel is a gradient of white to black, from left to right again. The third is a repeat of first line, the fourth line is a repeat of the second line and so on so forth. I want to flip every other(even) line so the gradient goes from black to white gradient, from left to right. Any help will be greatly appreciated, thanks.
Hang
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: flipping every other line of pixel in an image
I gather that your image description is just an example of what you want done, and that you don't actually want to just directly generate a gradient image from white to black, left to right.
First lets create your described example, sized to the builtin rose: image, 70x46 pixels so everyone has a working image for later.
If you have such an image, you could use it as a distortion map to remap other images! See IM examples, displacement maps
http://www.imagemagick.org/Usage/distor ... distortion
For exampe lets create a rose image with every line flipped...
and unflip the the same lines again.
Note that the restore operation is also its inverse. That is flip every second line operation, will do and undo itself!
Alturnativally rather than use a distortion map, you could try to do this directly!
That is flip the X location, based on if the Y location is even or odd.
First lets create your described example, sized to the builtin rose: image, 70x46 pixels so everyone has a working image for later.
Code: Select all
convert -size 1x70 gradient: -rotate 90 \( +clone -flop \) -append \
-write mpr:tile +delete \
-size 70x46 tile:mpr:tile line_flipped.png
http://www.imagemagick.org/Usage/distor ... distortion
For exampe lets create a rose image with every line flipped...
Code: Select all
convert rose: line_flipped.png -fx 'p{v*(w-1),j}' rose_lflip.png
Code: Select all
convert rose_lflip.png line_flipped.png -fx 'p{v*(w-1),j}' rose_restored.png
Alturnativally rather than use a distortion map, you could try to do this directly!
That is flip the X location, based on if the Y location is even or odd.
Code: Select all
convert rose: -fx 'xx=j&1?(w-1)-i:i; p{xx,j}' rose_lflip.png
convert rose_lflip.png -fx 'xx=j&1?(w-1)-i:i; p{xx,j}' rose_restored.png
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: flipping every other line of pixel in an image
Hmmm as a matter of interest.. WHY
What produced such a horrible image that has every second line flipped?
What produced such a horrible image that has every second line flipped?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: flipping every other line of pixel in an image
Thanks Anthony, I will try that out now and let you know how it works out.
Hang
Hang
Re: flipping every other line of pixel in an image
Hi Anthony,
Every time I try using the code you provide the following error message pop up,
Also when I create the line_flipped.png from the code you give, the following messages is display
convert: unable to open image `\(': No such file or directory.
convert: unable to open image `\)': No such file or directory.
convert: unable to open image `\': No such file or directory.
however, the line_flipped.png image is still created.
Hang
Every time I try using the code you provide
Code: Select all
convert rose: line_flipped.png -fx 'p{v*(w-1),j}' rose_lflip.png
, and it create 2 images called rose_lflip-0.png,the original rose image, and rose_lflip-1.png, the original gradient line_flipped.png.convert: unable to parse expression `p{v*(w-1),j}'.
Also when I create the line_flipped.png from the code you give, the following messages is display
convert: unable to open image `\(': No such file or directory.
convert: unable to open image `\)': No such file or directory.
convert: unable to open image `\': No such file or directory.
however, the line_flipped.png image is still created.
Hang
Re: flipping every other line of pixel in an image
This is an assignment that is giving at school.Hmmm as a matter of interest.. WHY
What produced such a horrible image that has every second line flipped?
The real image is not a gradient of black to white, from left to right. But a normal picture that has every line of pixel reverse.
Just wondering if anyone try the above code on the rose image to see if it works. I try this and it keeps giving me a message sayingAlturnativally rather than use a distortion map, you could try to do this directly!
That is flip the X location, based on if the Y location is even or odd.
Code:
convert rose: -fx 'xx=j&1?(w-1)-i:i; p{xx,j}' rose_lflip.png
convert rose_lflip.png -fx 'xx=j&1?(w-1)-i:i; p{xx,j}' rose_restored.png
C:\Program Files\ImageMagick-6.3.4-Q16>convert rose: -fx 'xx=j&1?(w-1)-i:i; p{xx,j}' rose_lflip.png
convert: option requires an argument `-fx'.
'1?' is not recognized as an internal or external command,
operable program or batch file.
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: flipping every other line of pixel in an image
In windows you need to use the double quote instead of the single quote:
Pete
Code: Select all
convert rose: -fx "xx=j&1?(w-1)-i:i; p{xx,j}" rose_lflip.png
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: flipping every other line of pixel in an image
Thanks el_supremo, I would not have guessed that was the problem from that error.
I tend to use single quotes as I use a UNIX machine (linux actually) and don't want too much of shell interaction.
For More specific 'DOS-isms' see...
http://www.imagemagick.org/Usage/feedback.html#windows
I tend to use single quotes as I use a UNIX machine (linux actually) and don't want too much of shell interaction.
For More specific 'DOS-isms' see...
http://www.imagemagick.org/Usage/feedback.html#windows
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/