Page 1 of 1

How to reset -region?

Posted: 2011-04-22T04:31:30-07:00
by whugemann
I am applying histogram corrections to three regions of the same image. After that, I want to draw a polyline onto the result. The code in the Windows batch file looks like this:

Code: Select all

convert %%~na-1.jpg ^
-region %WIDTH%x%STRIP%+0+0 -normalize ^
-region %WIDTH%x%IHEIGHT%+0+%STRIP% -contrast-stretch 2,0%%  -auto-gamma -sigmoidal-contrast 12,50%% ^
-region %WIDTH%x%STRIP%+0+%BOTTOM% -normalize ^
-region %WIDTH%x%HEIGHT%+0+0 ^
-stroke red -strokewidth 10 -draw "polyline !x0!,!y0! !x1!,!y1! !x2!,!y2! !x3!,!y3! !x0!,!y0!" c_%%~na-1.jpg
%WIDTH%, %HEIGHT% and alike are DOS variables which have been set previously. Having manipulated the three regions, I have to reset the region to the entire image via

Code: Select all

-region %WIDTH%x%HEIGHT%+0+0 ^
OK, that's easy, but isn't there an easier, dummy-proof way to do that? There is nothing like a +reset ...

Wolfgang Hugemann

Re: How to reset -region?

Posted: 2011-04-22T09:20:46-07:00
by whugemann
I just have had a stroke of genius ;-)
The solution is pretty simple: The option -region 100x100%+0+0 will select the entire image!
Wolfgang Hugemann

Re: How to reset -region?

Posted: 2011-04-22T23:34:21-07:00
by anthony
If it is the entire image their is no need to use region!

To end a region either use a non-simple option (multi-image processing operation) Or +region

See the IM examples I updated and added to just two weeks ago, fully explaining regions.
http://www.imagemagick.org/Usage/masking/#region

I found a bug (transparency handling during the region merger) during that update, so ensure you have the latest IM.


Also note that some of the internal workings of region is likely to change in IM v7 (development for which is just getting started, and may take a least a few months). In particular the virtual offset of regions may become important as a way of preserving the position the region is returned to in the original image. Currently virtual offset are not used for this.

Re: How to reset -region?

Posted: 2011-04-29T13:19:12-07:00
by whugemann
Sorry, but I suspected that there is nothing like a "+region" option in ImageMagick. (I erroneously wrote "+reset" instead.)

The Command Line Options page does not tell anything about there being a +region option. IM definitively crashes each time you use +region under Windows. This was my experience when I posed the question and I have just tested it again: IM crashes each time I mention "+region" ...

Wolfgang Hugemann

Re: How to reset -region?

Posted: 2011-04-29T13:47:24-07:00
by fmw42
I tried this with no crash or error on my Mac OSX Tiger IM 6.6.9.6 Q16

convert rose: +region rose_tmp.png


Fred

Re: How to reset -region?

Posted: 2011-04-29T19:17:52-07:00
by whugemann
I have tested the +region more thoroughly now, and found that Fred and Anthony are correct: +region resets any region settings (as I initially expected) and functions perfectly. I though still have to check what went wrong with it in my original script, where it made IM crash each time. I will come back on this and report.

Wollfgang

Re: How to reset -region?

Posted: 2011-04-30T03:03:32-07:00
by anthony
whugemann wrote:Sorry, but I suspected that there is nothing like a "+region" option in ImageMagick. (I erroneously wrote "+reset" instead.)

The Command Line Options page does not tell anything about there being a +region option. IM definitively crashes each time you use +region under Windows. This was my experience when I posed the question and I have just tested it again: IM crashes each time I mention "+region" ...

Wolfgang Hugemann
+region IS present, and working -- I have seen the code and used it.

But it does NOTHING unless you have previously used -region and it is still in effect. Region are automatically cancelled not only by +region but any multi-image list operator (like -compose) In this case even crop would cancel it even though it is classed as a 'simple' image operator.

It was a late addition during the hectic IM v5 to IMv6 conversion, whcih explains the lack of documentation. I even includes some basic usage examples of it (in 'image warping') however those examples has now moved to 'masking' as it is a sort of masking method (mask by cropping sub-images).



In IMv7 I would probably change it so it MUST be specifically cancelled (or produce an error), just as parenthesis must ve closed. Actually in many ways it works like parenthesis, though it actually pre-dates the implementation of parenthesis (added in the early days of IMv6).

ASIDE: I also plan to make using a image operation when no image is in memory an error, removing the current 'hairy' legacy handling where you can specify operations BEFORE you read or create images. This is actually a requirement for 'pipelined' or 'streaming' image operations, such as in a IM script that would make possible. You can't run, until you walk (or in this can have something to run on).

Re: How to reset -region?

Posted: 2011-04-30T03:07:34-07:00
by anthony
There was a small very recent bug fix for region, basically involving the composition of the sub-image. With the fix you can use it to modify transparency in the region (if the source image has transparency).

But other than that, it is working, and has always worked. It just wasn't must used as the example documentation on practical use was minimal.

Re: How to reset -region?

Posted: 2011-04-30T05:22:01-07:00
by whugemann
There was a small very recent bug fix for region.
This seems to be the explanation. I have used ImageMagick 6.6.3-0 2010-07-01 Q16 (Windows) on the computer where I originally tested the code. On this computer

Code: Select all

convert logo: -region 100x100+100+100 -negate +region -negate logo.png
causes ImageMagick to crash. I have just updated to the latest Version ImageMagick 6.6.9-6 2011-04-14 Q16 and now the same command line works perfectly.

Wolfgang Hugemann