How to reset -region?

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
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

How to reset -region?

Post 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
Wolfgang Hugemann
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to reset -region?

Post 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
Wolfgang Hugemann
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to reset -region?

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to reset -region?

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

Re: How to reset -region?

Post 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
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to reset -region?

Post 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
Wolfgang Hugemann
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to reset -region?

Post 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).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to reset -region?

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: How to reset -region?

Post 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
Wolfgang Hugemann
Post Reply