NConvert AutoCrop option after Rotate doesn't work

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

tigran
Posts: 6
Joined: Thu Jun 26, 2014 7:06 am

NConvert AutoCrop option after Rotate doesn't work

Post by tigran »

Hi there! XnView is a great masterpiece! I Use it with pleasure.

Will explain my Problem briefly:

I need to automatically rotate image on X degrees, so that black areas are automatically cropped.
I used these commands, neither of them helped so far.

nconvert.exe -rotate 10 -rotate_flag smooth -autocrop 0 0 0 0 1.jpg
nconvert.exe -rotate 10 -rotate_flag smooth -autocrop 255 0 0 0 1.jpg
nconvert.exe -autocrop 0 0 0 0 1.jpg // this is for already rotated image

I also tried to auto crop from XnView UI menu. It doesn't crop black area after rotation.

The only way it works - it is manually launch custom rotation with auto crop option from xnview image menu.

Is auto crop option (-rotate_flag auto crop) for custom rotation (-rotate degree) implemented in the command line for NConvert?

Please advice how to automatically crop rotated images
Last edited by tigran on Thu Jun 26, 2014 8:36 am, edited 2 times in total.
cday
XnThusiast
Posts: 3945
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: NConvert AutoCrop option after Rotate don't work

Post by cday »

Could you upload an example image that you need to process?
tigran
Posts: 6
Joined: Thu Jun 26, 2014 7:06 am

Re: NConvert AutoCrop option after Rotate don't work

Post by tigran »

here you go, this is just as a sample to explain the problem of black borders after rotation that are not cropped
You do not have the required permissions to view the files attached to this post.
cday
XnThusiast
Posts: 3945
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: NConvert AutoCrop option after Rotate doesn't work

Post by cday »

In general NConvert implements commands available in XnView, so developing a useable NConvert script is often conveniently done by first finding the XnView operations required to perform the action(s) required, and then debugging the command line script.
tigran wrote:The only way it works - it is manually launch custom rotation with auto crop option from xnview image menu.
I also tried to auto crop from XnView UI menu. It doesn't crop black area after rotation.
I think I've obtained about the XnView result that you need with the following operations:

1. Image > Rotate > Custom... : Background colour = Black (0,0,0) , angle = -2 degrees

2. Image > Automatic crop... : Background colour = Black (0,0,0) , Tolerance = 100 (For example)

Which produces the following image:
Armenian_Van_Cat_cday.jpg
Is this about the result you need?

Are the black edge areas in your original image that you wish to remove due to a previous rotation? If so, selecting a background colour for the rotation that more closely matches the colours in the image would reduce the unwanted effect, although likely not enough to be useful in general.

I'm not entirely clear about what you're trying to do, or whether, if a custom rotation is required in XnView, it is actually possible using NConvert...

Edit:

Is the image you uploaded the original image you started with, or the image after you made a custom rotation?
You do not have the required permissions to view the files attached to this post.
tigran
Posts: 6
Joined: Thu Jun 26, 2014 7:06 am

Re: NConvert AutoCrop option after Rotate doesn't work

Post by tigran »

Thanks for your reply, cday!
Is the image you uploaded the original image you started with, or the image after you made a custom rotation?

Your above quote is the answer.

It was altered image.

My Goal: original normal image -> rotate on some angle -> remove black triangle areas (crop). this should be done automatically.

Manually it can be done as I said in my 1st msg: open xnview -> image -> rotate-> custom -> set angle and turn on 'auto crop' option
tigran
Posts: 6
Joined: Thu Jun 26, 2014 7:06 am

Re: NConvert AutoCrop option after Rotate doesn't work

Post by tigran »

The problem in NConvert and XnView batch procesing is :

NConvert:
  • doesn't have auto crop option as a flag for -rotate_flag
  • separate -autocrop option, doesn't work for an image that I posted above (doesn't remove triangle black areas appeared after rotation)
XnView:
  • doesn't have 'auto crop' option for rotation in batch proceesing mode
  • manual autocrop option in Image menu, doesn't work for an image that I posted above (doesn't remove triangle black areas appeared after rotation)
cday
XnThusiast
Posts: 3945
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: NConvert AutoCrop option after Rotate doesn't work

Post by cday »

tigran wrote:It was altered image.
Thanks, could you upload the original image as that may make the overall problem clearer: sometimes a slightly different approach can be the best overall solution.

If a custom rotation is necessary for each image, clearly that can't be automated in NConvert, so it would only be possible to use the same fixed operations from that point on.

XnView also now has an auto-deskew option, if that would be useful in principle, but it doesn't process colour images...
tigran
Posts: 6
Joined: Thu Jun 26, 2014 7:06 am

Re: NConvert AutoCrop option after Rotate doesn't work

Post by tigran »

That is what I'm trying to automate:
You do not have the required permissions to view the files attached to this post.
cday
XnThusiast
Posts: 3945
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: NConvert AutoCrop option after Rotate doesn't work

Post by cday »

That's an excellent illustration that makes the problem clearer. :)

The first operation is a small rotation: do you want to automate that, using a fixed rotation angle, or to do a custom rotation for each image and then use NConvert for only the second operation?

The second operation could only be done using autocrop if the image is straightened first, as in the image I posted: autocrop crops each edge of the overall image in to the start of the image itself, and so produces a rectangular crop as if you had made a manual selection. You have probably seen that, but that is the way autocrop works...

The second operation as shown could be done as a simple crop using NConvert, but only if the same pixel settings could be used for each image.

A better solution would probably be to use -canvas , with the position 'pos' set to center : if the 'percent' option is used it should be possible to process images with different pixel dimensions using the same resize proportions.
tigran
Posts: 6
Joined: Thu Jun 26, 2014 7:06 am

Re: NConvert AutoCrop option after Rotate doesn't work

Post by tigran »

cday, you made my day, man :)

yep, I looped on the non-existent feature in batch mode for nconvert/xnview.

But it actually can be bypassed with canvas resizing nconvert option:

nconvert.exe -rotate 2 -canvas 90% 90% center Image.jpg

You should play with percentage that best matches chosen rotation angle.

Hope it will help somebody.