Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIPS commands #70

Closed
tst-mjibaly opened this issue Sep 5, 2013 · 13 comments
Closed

VIPS commands #70

tst-mjibaly opened this issue Sep 5, 2013 · 13 comments
Labels

Comments

@tst-mjibaly
Copy link

I've read the docs on resample, but I can't figure out how to rotate an image -0.20 degrees (i.e. 1/5th of a degree counter-clockwise).

Also:

  • how would I change the depth (from 16 to 8) with VIPS?
  • does VIPS have a 'normalize' command?
@tst-mjibaly
Copy link
Author

I tried to rotate a large TIFF image -0.20 degrees with nips2, but that didn't work (it would just change the value I entered to -0). However, I know this "transformation" is possible, because I'm able to do it with XnView.

image

@jcupitt
Copy link
Member

jcupitt commented Sep 6, 2013

Hi, use affine with the standard 2D matrix for rotation:

cos 20, sin 20
-sin 20, cos 20

At the command-line, that'd be:

vips affine shark.jpg x.v "0.94 0.342 -0.342 0.94"

In nip2, load the image, then click Image / Transform / Rotate / Free and drag the slider (or type a number).

To change to 16 bit, use:

vips cast x.jpg x.tif ushort

vips uses the C names for formats, so char and uchar are signed and unsigned 8 bit, short and ushort are signed and unsigned 16 bit, int and uint are signed and unsigned 32 bit, float and double are 32 and 64-bit floating point, and complex and dpcomplex are 64 and 128-bit complex.

What do you mean by normalise? Can you give an example?

@tst-mjibaly
Copy link
Author

Thanks for the response!

I don't have the affine command, only the im_affine command, and it wants more arguments.

┌─[mustafa@mustafa] - [~/Desktop] - []
└─[$]>vips --version
vips-7.28.5-Sat Mar  9 18:46:42 UTC 2013
┌─[mustafa@mustafa] - [~/Desktop] - []
└─[$]>vips im_affine
usage: vips im_affine in out a b c d dx dy x y w h 
where:
    in is of type "image"
    out is of type "image"
    a is of type "double"
    b is of type "double"
    c is of type "double"
    d is of type "double"
    dx is of type "double"
    dy is of type "double"
    x is of type "integer"
    y is of type "integer"
    w is of type "integer"
    h is of type "integer"
affine transform, from package "deprecated"
flags: (PIO function) (coordinate transformer) (area operation) (result can be cached) 
┌─[mustafa@mustafa] - [~/Desktop] - []
└─[$]>vips im_affine in.tif out.tif "0.94 0.342 -0.342 0.94"
im_run_command: too few arguments

Image normalization:

@jcupitt
Copy link
Member

jcupitt commented Sep 15, 2013

Try im_affinei_all:

$ vips im_affinei_all
usage: vips im_affinei_all in out interpolate a b c d dx dy 
where:
    in is of type "image"
    out is of type "image"
    interpolate is of type "interpolate"
    a is of type "double"
    b is of type "double"
    c is of type "double"
    d is of type "double"
    dx is of type "double"
    dy is of type "double"
affine transform of whole image, from package "resample"
flags: (PIO function) (coordinate transformer) (area operation) (result can be cached)```

Then something like:

vips im_affinei_all shark.jpg x.v bicubic 0.94 0.342 -0.342 0.94 0 0

dx/dy set a input-space translation, so zero is good for you.

For normalisation, try scale:

vips scale shark.jpg x.jpg

@tst-mjibaly
Copy link
Author

Thanks John!

Unfortunately, vips treats -0.342 as a flag, which causes the command to fail. I think (you would know better, of course) that I can use nip2's batch mode to rotate the image via the command line. I've read the rotate command's source code and spent some time reading the manual, but not enough it seems, because I'm still unsure how I should go about this. Could you please provide some direction? Thanks!

            rotate_widget default x = class
                _result {
                _vislevel = 3;

                angle = Option "Rotate by" [
                    "Don't rotate", 
                    "90 degrees clockwise",
                    "180 degrees",
                    "90 degrees anticlockwise"
                ] default;

                _result 
                    = map_unary process x
                {
                    process in = [
                        in, 
                        rot90 in,
                        rot180 in,
                        rot270 in
                    ] ? angle;
                }
            }

@jcupitt
Copy link
Member

jcupitt commented Sep 17, 2013

You might need a more recent vips, I think this is somthing that's been improved.

Try adding a space before the hyphen, eg.:

vips im_affinei_all shark.jpg x.v bicubic 0.94 0.342 " -0.342" 0.94 0 0

does that stop arg processing?

In nip2 it'd be something like:

#!/home/john/vips/bin/nip2 --script

interpolate = Interpolate Interpolate_type.BICUBIC [];
angle = parse_float argv?1;
image = Image_file argv?2;

main = rotate interpolate angle image;

Then run with:

./try201.nip2 -12 ~/pics/shark.jpg -o x.jpg

@tst-mjibaly
Copy link
Author

Yeah, I'm on a bit of an old release (7.28.5). The space fix worked, and I was able to successfully rotate the image -- thanks!

The nip2 script also worked, although I ran into the same problem with negative numbers, and adding a space didn't fix things (Symbol "angle" has no value.), so I just hard-coded the angle in the script. Maybe I'll just compile vips myself (the version in the Ubuntu repos is old).

@tst-mjibaly
Copy link
Author

If I wanted to crop (im_extract_area) and also convert to tiff (vips2tiff), is there a way to do this without creating a temp file?

@jcupitt
Copy link
Member

jcupitt commented Sep 17, 2013

Sure:

vips extract_area input.png output.tif 10 10 100 100

You can put options to file input-output arguments in square brackets at the end of the filename, eg.:

vips extract_area input.png output.tif[tile,compression=jpeg] 10 10 100 100

@tst-mjibaly
Copy link
Author

Hey, I've been trying for some time (and have done a fair amount of Googling/reading) and haven't been able to to get nip2 to run the rotate script from the command line (--script either needs a filename, or needs to be in a separate file).

Neither work:

  • nip2 --verbose -e 'rotate Interpolate Interpolate_type.BICUBIC 12 Image_file "in.jpg"' -o out.jpg
  • nip2 --verbose -e 'interpolate = Interpolate Interpolate_type.BICUBIC []; angle = 1; image = Image_file "in.jpg"; main = rotate interpolate angle image;' -o out.jpg

@jcupitt
Copy link
Member

jcupitt commented Sep 28, 2013

Try:

nip2 -e 'rotate (Interpolate Interpolate_type.BICUBIC []) 12 (Image_file "babe.jpg")' -o out.jpg

You need the brackets around Interpolate and Image_file.

Yes, the --script argument is for writing batch files with nip2 as the interpreter.

@tst-mjibaly
Copy link
Author

Excellent, that worked great!

Thanks!

@jcupitt jcupitt closed this as completed Oct 3, 2013
@jcupitt
Copy link
Member

jcupitt commented Oct 3, 2013

I've added a simple thing to master to make this easier from the command-line: jcupitt@439522a

You can now do things like:

vips similarity sarto_ng.v x.v --angle 20 --scale 1.1

It just calls vips_affine() for you, calculating the transform matrix from the scale and angle parameters. Other params are as vips_affine().

It'll be in the next stable version, due in a couple of weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants