use identify and convert in same command? mpr: format. windows batch file.

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
josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

use identify and convert in same command? mpr: format. windows batch file.

Post by josephaaroncampbell »

Hello,

Is it possible to use the covert and identify commands in the same command string?

I need to apply settings to an .tiff image file but also want to know the mean and other stats about the images AFTER the settings are applied.

I was hoping to avoid writing the file to disk.

I tried the mpr: format hoping this would work but it did not.
I tried the -write command but maybe dont understand it very well.

so example:

-the settings i am applying in the normal covert command:

Code: Select all

magick convert -quiet -colorspace GRAY  -gamma %gNum1%  -sigmoidal-contrast  %fact%,%sNum1%%%  +level 0%%,98%%  -depth 8 %fullPathtoTIFF%  output.tiff
-then to use identify

Code: Select all

magick identify output.tiff -format "Mean1=%%[fx: mean]" xc:

I have tried to string them together but i get errors sting 'identify' is not a recognized command... for example

Code: Select all

magick convert -quiet -colorspace GRAY  -gamma %gNum1%  -sigmoidal-contrast  %fact%,%sNum1%%%  +level 0%%,98%%  -depth 8 %fullPathtoTIFF%  mpr:holder ^

identify mpr:holder -format  "Mean1=%%[fx: mean]" xc:

I've checked the batch usage page and am reading through some if its content. but is there a way to load an edited image into memory and return its mean or statistics without saving the file to disk?

Thank You.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: use identify and convert in same command? mpr: format. windows batch file.

Post by snibgo »

Code: Select all

magick convert -quiet -colorspace GRAY -gamma %gNum1% -sigmoidal-contrast %fact%,%sNum1%%% +level 0%%,98%% -depth 8 %fullPathtoTIFF% output.tiff
That command is bad syntax. You should read the input, then process it, then write the output.

Code: Select all

magick convert -quiet %fullPathtoTIFF% -colorspace GRAY -gamma %gNum1% -sigmoidal-contrast %fact%,%sNum1%%% +level 0%%,98%% -depth 8 output.tiff
"+write info:" will write whatever info is in the current format string, so you can put that before the output image filename.

Code: Select all

magick convert -quiet %fullPathtoTIFF% -colorspace GRAY -gamma %gNum1% -sigmoidal-contrast %fact%,%sNum1%%% +level 0%%,98%% -depth 8 -format "Mean1=%%[fx:mean]\nStdDev=%%[fx:standard_deviation]" +write info: output.tiff
You can wrap that inside a FOR loop to get environment variables called "Mean1" and "StdDev".
snibgo's IM pages: im.snibgo.com
josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

Re: use identify and convert in same command? mpr: format. windows batch file.

Post by josephaaroncampbell »

Thank you for the response. sorry for the delay in mine.

this works very well.
josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

Re: use identify and convert in same command? mpr: format. windows batch file.

Post by josephaaroncampbell »

I also ended up using the mpr format with '-write' like this:

**from windows batch file:

Code: Select all

 magick convert -quiet !fullpath! %~dp0clut.tif -clut -colorspace gray -gamma !gNum! -gravity center -crop 60%% -write mpr:hgram +delete mpr:hgram -format %%c histogram:info:- >> %~dp0hist.txt
this is to output the histogram data as if edits were applied to image to see how the edits effect the image data.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: use identify and convert in same command? mpr: format. windows batch file.

Post by snibgo »

That will work fine, but this sequence:

Code: Select all

-write mpr:hgram +delete mpr:hgram
... is entirely redundant. It takes a little time but does nothing useful.
snibgo's IM pages: im.snibgo.com
josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

Re: use identify and convert in same command? mpr: format. windows batch file.

Post by josephaaroncampbell »

I will test it out. I was doing it without the mpr before but didnt see any changes in the histogram. so maybe i was overlooking something then.

thanks for the info
josephaaroncampbell
Posts: 40
Joined: 2015-07-14T19:18:45-07:00
Authentication code: 1151
Location: Chicago, IL

Re: use identify and convert in same command? mpr: format. windows batch file.

Post by josephaaroncampbell »

confirmed. This works just fine with out the added MPR.

Thank for making this more efficient.
Post Reply