Exif Image Height[Width] values differ from Image Height[Width] values

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?".
vermonster
Posts: 7
Joined: 2015-02-12T14:20:49-07:00
Authentication code: 6789

Exif Image Height[Width] values differ from Image Height[Width] values

Post by vermonster » 2015-02-12T14:39:53-07:00

Using either convert or mogrify to resize images, I see that in the resulting images, the values for the Exif Image Height(Width) and the Image Height(Width) values as reported by ExifTool differ: Exif Image Height(Width) has the value for the original image, whereas Image Height(Width) has the value for the resized image. Why?

Exif Image Width is tag 0xa002, "PixelXDimension"
Exif Image Height is tag 0xa003, "PixelYDimension"

Using Version: ImageMagick 6.8.9-6 Q8 x64 2014-07-22 http://www.imagemagick.org

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by Bonzo » 2015-02-12T15:07:54-07:00

What command are you using?

You could try adding +repage before the image save and see if that has an effect.

vermonster
Posts: 7
Joined: 2015-02-12T14:20:49-07:00
Authentication code: 6789

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by vermonster » 2015-02-12T18:23:31-07:00

I observed this using both "convert" and "mogrify".

snibgo
Posts: 11932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by snibgo » 2015-02-12T18:37:26-07:00

Please say how we can find "the values for the Exif Image Height(Width) and the Image Height(Width) values".
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by fmw42 » 2015-02-12T18:50:15-07:00

What is your exact command? Perhaps you should post your image to dropbox.com and put the URL here so we can see what you are doing? We presume you are getting the width and height from EXIFTOOL and also from ImageMagick, but is it the very same image. What part of identify -verbose are you using to get the Imagemagick width and height? If you have cropped the image or trimmed the image, you need to add +repage before the output to remove the virtual canvas. What is your input format? Some formats such and PNG and perhaps TIFF carry virtual canvas settings that show the original size and where it has been cropped as part of the IM geometry meta data.

vermonster
Posts: 7
Joined: 2015-02-12T14:20:49-07:00
Authentication code: 6789

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by vermonster » 2015-02-12T19:28:25-07:00

The command was mogrify -resize 2048x2048; I was then using exiftool to look at the metadata. Exiftool reports both an Exif Image Height/Width value as well as an Image Height/Width value.

For background, I have a very large collection of images that I had resized using the mogrify command; I was trying to run these images through some other image processing library, and that library was getting confused about the image dimensions, specifically, it was reporting the image dimensions as being the dimensions of the original (parent) image although I was using the resized images. In an attempt to figure out what was going on, I used Exiftool to look at the actual metadata values, and that's when I saw the discrepancy---the image metadata in the files created by mogrify were inconsistent.

Clearly, the right values are the Image Height/Width values, but unfortunately the other image processing library appears to be giving precedence to the Exif values. That may very well be a bug in that (other) library, but I don't understand why the files generated by ImageMagick have these two different sets of values. Is it by design or is it a bug in ImageMagick?

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by fmw42 » 2015-02-12T19:34:01-07:00

Code: Select all

mogrify -resize 2048x2048
That is not a fully specified command. What is the exact command and what image formats are you using? Are you changing the format?

Perhaps upload one or two images to dropbox.com and put the URLs here, so we can test your exact command.

Perhaps upgrade IM to the latest version and whatever format delegates are needed for your images?

What platform?

Can you post the commands you used to get the image dimensions both ways? Also show the output from EXIFTOOL and Imagemagick convert or identify, if those were what you used to get dimensions.
I don't understand why the files generated by ImageMagick have these two different sets of values. Is it by design or is it a bug in ImageMagick?
Cannot say until we understand exactly what you are doing to get the values!

snibgo
Posts: 11932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by snibgo » 2015-02-12T19:36:12-07:00

vermonster wrote:Exiftool reports both an Exif Image Height/Width value as well as an Image Height/Width value.
Please say the exact command you used, with the output. Ideally also provide an image that shows the problem.
snibgo's IM pages: im.snibgo.com

vermonster
Posts: 7
Joined: 2015-02-12T14:20:49-07:00
Authentication code: 6789

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by vermonster » 2015-02-14T16:13:17-07:00

I updated to the latest version of ImageMagick (6.9.0-5 Q16 x86 2015-01-31) & Exiftool (9.85).

Here's the result of running Exiftool on the image, before I "mogrified" it (for simplicity, just showing height):

Code: Select all

C:\Apps\test>..\exiftool-9.85\exiftool.exe -H DSC_1082.JPG "-*Height*"
0xa003 Exif Image Height               : 3072
     - Image Height                    : 3072
I then resized the image with the following command:

Code: Select all

C:\Apps\test>..\ImageMagick-6.9.0-5\mogrify.exe -resize 1024x1024 DSC_1082.JPG
and then reran Exiftool to get the height values again:

Code: Select all

C:\Apps\test>..\exiftool-9.85\exiftool.exe -H DSC_1082.JPG "-*Height*"
0xa003 Exif Image Height               : 3072
     - Image Height                    : 683
Here's a copy of the original image (a copy, since I mogrified the original): https://www.dropbox.com/s/31i0xcvywmf4g ... g.JPG?dl=0

And here's a copy of the resized image: https://www.dropbox.com/s/2vfbrizxwrq5b ... 2.JPG?dl=0

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by fmw42 » 2015-02-14T16:49:16-07:00

iM 6.9.0.5 Q16 Mac OSX 10.6.8 Snow Leopard

exiftool -ver
8.71


It is all consistent for me.


identify DSC_1082_Orig.JPG
DSC_1082_Orig.JPG JPEG 4608x3072 4608x3072+0+0 8-bit sRGB 4.972MB 0.000u 0:00.000


exiftool -s -ee -g1 -u -n -D DSC_1082_Orig.JPG
- ImageWidth : 4608
- ImageHeight : 3072


convert DSC_1082_Orig.JPG -resize 1024x1024 tmp.jpg
identify tmp.jpg
tmp.jpg JPEG 1024x683 1024x683+0+0 8-bit sRGB 517KB 0.000u 0:00.000

exiftool -s -ee -g1 -u -n -D tmp.jpg
- ImageWidth : 1024
- ImageHeight : 683


cd
cd desktop/tmpdir1
mogrify -format JPG -path ../tmpdir2 -resize 1024x1024 *.JPG

cd
cd desktop
identify tmpdir2/DSC_1082_Orig.JPG
tmpdir2/DSC_1082_Orig.JPG JPEG 1024x683 1024x683+0+0 8-bit sRGB 517KB 0.000u 0:00.000

exiftool -s -ee -g1 -u -n -D tmpdir2/DSC_1082_Orig.JPG
- ImageWidth : 1024
- ImageHeight : 683


cd
cd desktop
mogrify -format JPG -resize 1024x1024 DSC_1082_Orig.JPG


identify DSC_1082_Orig.JPG
DSC_1082_Orig.JPG JPEG 1024x683 1024x683+0+0 8-bit sRGB 517KB 0.000u 0:00.000


exiftool -s -ee -g1 -u -n -D tmpdir2/DSC_1082_Orig.JPG
- ImageWidth : 1024
- ImageHeight : 683

vermonster
Posts: 7
Joined: 2015-02-12T14:20:49-07:00
Authentication code: 6789

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by vermonster » 2015-02-14T17:06:56-07:00

I'm sorry, what's consistent? Does your ExifImageHeight value match the ImageHeight value?

I get the following using your exiftool parameters:

Code: Select all

C:\Apps\test>..\exiftool-9.85\exiftool.exe -s -ee -g1 -u -n -D DSC_1082.JPG | fi
ndstr Height
    - ImageHeight                     : 683
40963 ExifImageHeight                 : 3072
The problem is that there are two different tags giving the height (or width) values, and those values do not agree. Your example above isn't showing the Exif versions of the properties.

Thanks for looking into this.

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by fmw42 » 2015-02-14T18:59:08-07:00

I suspect those two arguments means something else. It is wrong, if it means the actual image height in pixels. Perhaps that is the maximum size of the sensor array in the camera. But I am not expert on EXIF.

Clearly they are not the correct arguments to be compared with the IM width and height.

If you want a clear understanding of those arguments, then ask on an EXIF forum.


see http://www.awaresystems.be/imaging/tiff ... nsion.html

Code: Select all

convert DSC_1082_Orig.JPG -resize 1024x1024 tmp.jpg
exiftool -s -ee -g1 -u -n -D tmp.jpg
---- ExifTool ----
- ExifToolVersion : 8.71
---- System ----
- FileName : tmp.jpg
- Directory : .
- FileSize : 518699
- FileModifyDate : 2015:02:14 17:48:24-08:00
- FilePermissions : 644
---- File ----
- FileType : JPEG
- MIMEType : image/jpeg
- CurrentIPTCDigest : 2613b278d68ac13a3f0e19c0c6fe5977
- ExifByteOrder : MM
- ImageWidth : 1024
- ImageHeight : 683
- EncodingProcess : 0
- BitsPerSample : 8
- ColorComponents : 3
- YCbCrSubSampling : 2 1
---- JFIF ----
0 JFIFVersion : 1 1
2 ResolutionUnit : 1
3 XResolution : 300
5 YResolution : 300
---- IPTC ----
80 By-line : Mark D. Wood
116 CopyrightNotice : (C)2011 Mark D. Wood, all rights reserved
---- IFD0 ----
271 Make : NIKON CORPORATION
272 Model : NIKON D3100
274 Orientation : 1
282 XResolution : 300
283 YResolution : 300
296 ResolutionUnit : 2
305 Software : ViewNX 2.1 W
306 ModifyDate : 2011:05:30 12:02:40
531 YCbCrPositioning : 1
---- ExifIFD ----
33434 ExposureTime : 0.03333333333
33437 FNumber : 3.5
34850 ExposureProgram : 2
34855 ISO : 200
36864 ExifVersion : 0221
36867 DateTimeOriginal : 2011:05:26 15:35:28
36868 CreateDate : 2011:05:26 15:35:28
37121 ComponentsConfiguration : 1 2 3 0
37380 ExposureCompensation : 0
37381 MaxApertureValue : 1.74110112659225
37383 MeteringMode : 5
37384 LightSource : 0
37385 Flash : 0
37386 FocalLength : 35
37510 UserComment :
37520 SubSecTime : 10
37521 SubSecTimeOriginal : 10
37522 SubSecTimeDigitized : 10
40960 FlashpixVersion : 0100
40961 ColorSpace : 1
40962 ExifImageWidth : 4608
40963 ExifImageHeight : 3072

41495 SensingMethod : 2
41728 FileSource : 3
41729 SceneType : 1
41730 CFAPattern : 2 2 1 2 0 1
41985 CustomRendered : 0
41986 ExposureMode : 0
41987 WhiteBalance : 0
41988 DigitalZoomRatio : 1
41989 FocalLengthIn35mmFormat : 52
41990 SceneCaptureType : 0
41991 GainControl : 0
41992 Contrast : 0
41993 Saturation : 0
41994 Sharpness : 0
41996 SubjectDistanceRange : 0
---- Nikon ----
1 MakerNoteVersion : 0210
2 ISO : 0 200
4 Quality : FINE
5 WhiteBalance : AUTO
7 FocusMode : AF-S
11 WhiteBalanceFineTune : 0 0
12 WB_RBLevels : 1 3.15234375 2.00390625 7.93359375
13 ProgramShift : -0.333333333333333
14 ExposureDifference : 0
19 ISOSetting : 0 200
22 ImageBoundary : 0 0 4608 3072
27 CropHiSpeed : 0 4672 3084 4672 3084 0 0
28 ExposureTuning : 0
29 SerialNumber : 3013267
30 ColorSpace : 1
0 VRInfoVersion : 0100
4 VibrationReduction : 2
34 ActiveD-Lighting : 0
0 PictureControlVersion : 0100
4 PictureControlName : STANDARD
24 PictureControlBase : STANDARD
48 PictureControlAdjust : 0
49 PictureControlQuickAdjust : 0
50 Sharpness : 3
51 Contrast : 0
52 Brightness : 0
53 Saturation : 0
54 HueAdjustment : 0
55 FilterEffect : 255
56 ToningEffect : 255
57 ToningSaturation : 127
0 Timezone : -300
2 DaylightSavings : 0
3 DateDisplayFormat : 0
0 ISO : 200
4 ISOExpansion : 0
6 ISO2 : 200
10 ISOExpansion2 : 0
0 DistortionVersion : 0100
4 AutoDistortionControl : 0
0 UnknownInfoVersion : 0101
45 Nikon_0x002d : 512 0 0
131 LensType : 6
132 Lens : 35 35 1.8 1.8
135 FlashMode : 0
137 ShootingMode : 0
138 Nikon_0x008a : 1
139 LensFStops : 7.33333333333333
0 ShotInfoVersion : 0219
4 FirmwareVersion : 1.01b
149 NoiseReduction : OFF
0 WB_GRBGLevels : 154 4205 515 4883
0 LensDataVersion : 0204
4 ExitPupilPosition : 102.4
5 AFAperture : 1.83400808640934
8 FocusPosition : 17
10 FocusDistance : 0.530884444230988
11 FocalLength : 35.6359487256136
12 LensIDNumber : 159
13 LensFStops : 7.33333333333333
14 MinFocalLength : 35.6359487256136
15 MaxFocalLength : 35.6359487256136
16 MaxApertureAtMinFocal : 1.78179743628068
17 MaxApertureAtMaxFocal : 1.78179743628068
18 MCUVersion : 161
19 EffectiveMaxAperture : 1.78179743628068
157 Nikon_0x009d : 0
158 RetouchHistory : 0
162 ImageDataSize : 4922370
163 Nikon_0x00a3 : 0
167 ShutterCount : 1097
171 VariProgram :
0 MultiExposureVersion : 0100
1 MultiExposureMode : 0
2 MultiExposureShots : 0
3 MultiExposureAutoGain : 0
177 HighISONoiseReduction : 0
182 PowerUpTime : 2011:05:26 15:35:21
0 AFInfo2Version : 0100
4 ContrastDetectAF : 0
5 AFAreaMode : 8
6 PhaseDetectAF : 2
7 PrimaryAFPoint : 1
8 AFPointsUsed : 129
28 ContrastDetectAFInFocus : 0
0 FileInfoVersion : 0100
6 DirectoryNumber : 100
8 FileNumber : 1082
187 Nikon_0x00bb : 0200???
3618 NEFBitDepth : 0 0 0 0
---- PreviewIFD ----
259 Compression : 6
282 XResolution : 72
283 YResolution : 72
296 ResolutionUnit : 2
513 PreviewImageStart : 21121
514 PreviewImageLength : 23462
---- InteropIFD ----
1 InteropIndex : R98
2 InteropVersion : 0100
---- GPS ----
0 GPSVersionID : 2 2 0 0
---- IFD1 ----
259 Compression : 6
282 XResolution : 300
283 YResolution : 300
296 ResolutionUnit : 2
513 ThumbnailOffset : 12334
514 ThumbnailLength : 8787
---- XMP-x ----
- XMPToolkit : XMP Core 4.1.1
---- XMP-dc ----
- Creator : Mark D. Wood
- Rights : (C)2011 Mark D. Wood, all rights reserved
---- XMP-iptcCore ----
- CreatorCity : Penfield
- CreatorCountry : USA
- CreatorRegion : NY
---- XMP-microsoft ----
- RatingPercent : 0
---- XMP-photoshop ----
- Urgency : 6
---- XMP-xmpRights ----
- UsageTerms : For consideration only, no reproduction without prior permission
---- XMP-xmp ----
- Label : Blue
---- Composite ----
- Aperture : 3.5
- AutoFocus : 1
- BlueBalance : 0.204486797697042
- ImageSize : 1024x683
- LensID : 9F 58 44 44 14 14 A1 06
- LensSpec : 35 35 1.8 1.8 6
- PreviewImage : (Binary data 23462 bytes, use -b option to extract)
- RedBalance : 1.66964462973992
- ScaleFactor35efl : 1.48571428571429
- ShutterSpeed : 0.03333333333
- SubSecCreateDate : 2011:05:26 15:35:28.10
- SubSecDateTimeOriginal : 2011:05:26 15:35:28.10
- SubSecModifyDate : 2011:05:30 12:02:40.10
- ThumbnailImage : (Binary data 8787 bytes, use -b option to extract)
- CircleOfConfusion : 0.0202234446540448
- DOF : 0.516096808473498 0.546544492396619
- FOV : 35.8354643365154 0.343304615236837
- FocalLength35efl : 52.0000000000001
- HyperfocalDistance : 17.3066461222272
- LightValue : 7.521600439868

snibgo
Posts: 11932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by snibgo » 2015-02-14T20:27:29-07:00

I get the same results as the OP, from both mogrify and convert. Eg, after convert resize:

Code: Select all

f:\web\im>exiftool -s -ee -g1 -u -n -D x1.jpg |cgrep /i- /sheight /g /o-

    - ImageHeight                     : 683
40963 ExifImageHeight                 : 3072
The Exif version 2.3 standard (http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf ) says 0xA002 and 0xA003 (PixelXDimension and PixelYDimension) are not always present.

IM isn't good at updating Exif data. It seems to me that IM should update these tags, but a developer would need to comment.
snibgo's IM pages: im.snibgo.com

User avatar
dlemstra
Posts: 1563
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by dlemstra » 2015-02-15T03:52:34-07:00

We update some exif tags but this one is not part of those that are updated. I already did a bit research when I noticed a similar stackoverflow question. It seems we should only keep it there when the file is (jpeg?) compressed. This is explained on page 31/45 of the Exif version 2.3 standard (its called PixelXDimension and PixelYDimension). We could update the value in the exif profile or remove it right before the file is written. Updating is not that difficult but I don't know when we should remove the value. Is this tag only valid for .jpeg files?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

snibgo
Posts: 11932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Exif Image Height[Width] values differ from Image Height[Width] values

Post by snibgo » 2015-02-15T04:59:55-07:00

From my understanding of the Exif standard, if the file is not compressed then neither PixelXDimension nor PixelYDimension should be present. If the file is compressed (lossy or not), the fields should record the correct number of pixels.
snibgo's IM pages: im.snibgo.com

Post Reply