Shell test for “images are different”?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
In a shell script, I would like to check whether two PNG images are different in the sense that either the images have different sizes or at least one pixel of one image has a different RGBA than the corresponding pixel of the other image.
Hashing the two image files will not work because the images could be compressed differently or have a different comment or perhaps two pixels are fully transparent but the RGB components differ, etc.
I know how to check whether the file sizes are different using ImageMagick's convert
utility. As far as comparing the pixel values, I thought of using ImageMagick's compare
utility, but the exit code is always 0 if the command was successfully processed: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22451
What command line test can be used to compare the pixels of two PNG images for equality? Or perhaps there is a way to use compare
after all?
image bash shell imagemagick diff
add a comment |
In a shell script, I would like to check whether two PNG images are different in the sense that either the images have different sizes or at least one pixel of one image has a different RGBA than the corresponding pixel of the other image.
Hashing the two image files will not work because the images could be compressed differently or have a different comment or perhaps two pixels are fully transparent but the RGB components differ, etc.
I know how to check whether the file sizes are different using ImageMagick's convert
utility. As far as comparing the pixel values, I thought of using ImageMagick's compare
utility, but the exit code is always 0 if the command was successfully processed: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22451
What command line test can be used to compare the pixels of two PNG images for equality? Or perhaps there is a way to use compare
after all?
image bash shell imagemagick diff
add a comment |
In a shell script, I would like to check whether two PNG images are different in the sense that either the images have different sizes or at least one pixel of one image has a different RGBA than the corresponding pixel of the other image.
Hashing the two image files will not work because the images could be compressed differently or have a different comment or perhaps two pixels are fully transparent but the RGB components differ, etc.
I know how to check whether the file sizes are different using ImageMagick's convert
utility. As far as comparing the pixel values, I thought of using ImageMagick's compare
utility, but the exit code is always 0 if the command was successfully processed: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22451
What command line test can be used to compare the pixels of two PNG images for equality? Or perhaps there is a way to use compare
after all?
image bash shell imagemagick diff
In a shell script, I would like to check whether two PNG images are different in the sense that either the images have different sizes or at least one pixel of one image has a different RGBA than the corresponding pixel of the other image.
Hashing the two image files will not work because the images could be compressed differently or have a different comment or perhaps two pixels are fully transparent but the RGB components differ, etc.
I know how to check whether the file sizes are different using ImageMagick's convert
utility. As far as comparing the pixel values, I thought of using ImageMagick's compare
utility, but the exit code is always 0 if the command was successfully processed: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22451
What command line test can be used to compare the pixels of two PNG images for equality? Or perhaps there is a way to use compare
after all?
image bash shell imagemagick diff
image bash shell imagemagick diff
asked Apr 22 '13 at 15:05
Daniel TrebbienDaniel Trebbien
28.3k1192169
28.3k1192169
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Find an image format which allows uncompressed RGBA, convert both files, and compare the output. Maybe something like this:
$ convert a.png a.rgba
$ convert b.png b.rgba
$ cmp {a,b}.rgba
a.rgba b.rgba differ: byte 1, line 1
add a comment |
another way using ImageMagick and grep
compare -compose src -highlight-color "#FF0000FF" -lowlight-color "#00000000" a.png b.png delta.png
convert delta.png -define histograme:unique-colors=true -format %c histogram:info:- > histogram.info
if grep --quiet "#FF0000 red" histogram.info : then
echo "different"
else
echo "same"
fi
while this methodology relies on ImageMagick being installed, and is heavier than cmp it may be easier to expand to allow for tolerance etc...
TIPSdisplay -version
is a quick way to test if ImageMagick is already installed.
These commands could also be piped together if you want to avoid writing to disk.
add a comment |
You should not use the exit code from ImageMagick compare. All that says is the compare function exited successfully with no error. You want to report the AE metric from compare, which will tell you how many pixels are different. Or use some other metric such MAE or RMSE.
compare -metric AE image1 image2 null:
That will return a value to the terminal, which is the count.
For example:
compare -metric AE lena.png lena.jpg null:
65100
65100 pixels are different
You can return that to a variable as:
var=`compare -metric AE lena.png lena.jpg null: 2>&1`
echo $var
65100
ImageMagick write its output to stderr, so that is why I added 2>&1
See
https://imagemagick.org/script/compare.php
https://imagemagick.org/Usage/compare/
add a comment |
2 foundamental steps:
Recognize image format (gif, png, jpeg, ...). This can be done by file extension, if image files are "trustable" or in some other kind of way.
Find image properties, that are specific image format informations, stored into processed file. You can find infos about file and generic data formats from Wotsit.org.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16150434%2fshell-test-for-images-are-different%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Find an image format which allows uncompressed RGBA, convert both files, and compare the output. Maybe something like this:
$ convert a.png a.rgba
$ convert b.png b.rgba
$ cmp {a,b}.rgba
a.rgba b.rgba differ: byte 1, line 1
add a comment |
Find an image format which allows uncompressed RGBA, convert both files, and compare the output. Maybe something like this:
$ convert a.png a.rgba
$ convert b.png b.rgba
$ cmp {a,b}.rgba
a.rgba b.rgba differ: byte 1, line 1
add a comment |
Find an image format which allows uncompressed RGBA, convert both files, and compare the output. Maybe something like this:
$ convert a.png a.rgba
$ convert b.png b.rgba
$ cmp {a,b}.rgba
a.rgba b.rgba differ: byte 1, line 1
Find an image format which allows uncompressed RGBA, convert both files, and compare the output. Maybe something like this:
$ convert a.png a.rgba
$ convert b.png b.rgba
$ cmp {a,b}.rgba
a.rgba b.rgba differ: byte 1, line 1
answered Apr 22 '13 at 16:05
PhilPhil
3,97111420
3,97111420
add a comment |
add a comment |
another way using ImageMagick and grep
compare -compose src -highlight-color "#FF0000FF" -lowlight-color "#00000000" a.png b.png delta.png
convert delta.png -define histograme:unique-colors=true -format %c histogram:info:- > histogram.info
if grep --quiet "#FF0000 red" histogram.info : then
echo "different"
else
echo "same"
fi
while this methodology relies on ImageMagick being installed, and is heavier than cmp it may be easier to expand to allow for tolerance etc...
TIPSdisplay -version
is a quick way to test if ImageMagick is already installed.
These commands could also be piped together if you want to avoid writing to disk.
add a comment |
another way using ImageMagick and grep
compare -compose src -highlight-color "#FF0000FF" -lowlight-color "#00000000" a.png b.png delta.png
convert delta.png -define histograme:unique-colors=true -format %c histogram:info:- > histogram.info
if grep --quiet "#FF0000 red" histogram.info : then
echo "different"
else
echo "same"
fi
while this methodology relies on ImageMagick being installed, and is heavier than cmp it may be easier to expand to allow for tolerance etc...
TIPSdisplay -version
is a quick way to test if ImageMagick is already installed.
These commands could also be piped together if you want to avoid writing to disk.
add a comment |
another way using ImageMagick and grep
compare -compose src -highlight-color "#FF0000FF" -lowlight-color "#00000000" a.png b.png delta.png
convert delta.png -define histograme:unique-colors=true -format %c histogram:info:- > histogram.info
if grep --quiet "#FF0000 red" histogram.info : then
echo "different"
else
echo "same"
fi
while this methodology relies on ImageMagick being installed, and is heavier than cmp it may be easier to expand to allow for tolerance etc...
TIPSdisplay -version
is a quick way to test if ImageMagick is already installed.
These commands could also be piped together if you want to avoid writing to disk.
another way using ImageMagick and grep
compare -compose src -highlight-color "#FF0000FF" -lowlight-color "#00000000" a.png b.png delta.png
convert delta.png -define histograme:unique-colors=true -format %c histogram:info:- > histogram.info
if grep --quiet "#FF0000 red" histogram.info : then
echo "different"
else
echo "same"
fi
while this methodology relies on ImageMagick being installed, and is heavier than cmp it may be easier to expand to allow for tolerance etc...
TIPSdisplay -version
is a quick way to test if ImageMagick is already installed.
These commands could also be piped together if you want to avoid writing to disk.
answered Nov 16 '18 at 19:02
Brian DavisBrian Davis
15518
15518
add a comment |
add a comment |
You should not use the exit code from ImageMagick compare. All that says is the compare function exited successfully with no error. You want to report the AE metric from compare, which will tell you how many pixels are different. Or use some other metric such MAE or RMSE.
compare -metric AE image1 image2 null:
That will return a value to the terminal, which is the count.
For example:
compare -metric AE lena.png lena.jpg null:
65100
65100 pixels are different
You can return that to a variable as:
var=`compare -metric AE lena.png lena.jpg null: 2>&1`
echo $var
65100
ImageMagick write its output to stderr, so that is why I added 2>&1
See
https://imagemagick.org/script/compare.php
https://imagemagick.org/Usage/compare/
add a comment |
You should not use the exit code from ImageMagick compare. All that says is the compare function exited successfully with no error. You want to report the AE metric from compare, which will tell you how many pixels are different. Or use some other metric such MAE or RMSE.
compare -metric AE image1 image2 null:
That will return a value to the terminal, which is the count.
For example:
compare -metric AE lena.png lena.jpg null:
65100
65100 pixels are different
You can return that to a variable as:
var=`compare -metric AE lena.png lena.jpg null: 2>&1`
echo $var
65100
ImageMagick write its output to stderr, so that is why I added 2>&1
See
https://imagemagick.org/script/compare.php
https://imagemagick.org/Usage/compare/
add a comment |
You should not use the exit code from ImageMagick compare. All that says is the compare function exited successfully with no error. You want to report the AE metric from compare, which will tell you how many pixels are different. Or use some other metric such MAE or RMSE.
compare -metric AE image1 image2 null:
That will return a value to the terminal, which is the count.
For example:
compare -metric AE lena.png lena.jpg null:
65100
65100 pixels are different
You can return that to a variable as:
var=`compare -metric AE lena.png lena.jpg null: 2>&1`
echo $var
65100
ImageMagick write its output to stderr, so that is why I added 2>&1
See
https://imagemagick.org/script/compare.php
https://imagemagick.org/Usage/compare/
You should not use the exit code from ImageMagick compare. All that says is the compare function exited successfully with no error. You want to report the AE metric from compare, which will tell you how many pixels are different. Or use some other metric such MAE or RMSE.
compare -metric AE image1 image2 null:
That will return a value to the terminal, which is the count.
For example:
compare -metric AE lena.png lena.jpg null:
65100
65100 pixels are different
You can return that to a variable as:
var=`compare -metric AE lena.png lena.jpg null: 2>&1`
echo $var
65100
ImageMagick write its output to stderr, so that is why I added 2>&1
See
https://imagemagick.org/script/compare.php
https://imagemagick.org/Usage/compare/
answered Nov 17 '18 at 1:02
fmw42fmw42
8,70041831
8,70041831
add a comment |
add a comment |
2 foundamental steps:
Recognize image format (gif, png, jpeg, ...). This can be done by file extension, if image files are "trustable" or in some other kind of way.
Find image properties, that are specific image format informations, stored into processed file. You can find infos about file and generic data formats from Wotsit.org.
add a comment |
2 foundamental steps:
Recognize image format (gif, png, jpeg, ...). This can be done by file extension, if image files are "trustable" or in some other kind of way.
Find image properties, that are specific image format informations, stored into processed file. You can find infos about file and generic data formats from Wotsit.org.
add a comment |
2 foundamental steps:
Recognize image format (gif, png, jpeg, ...). This can be done by file extension, if image files are "trustable" or in some other kind of way.
Find image properties, that are specific image format informations, stored into processed file. You can find infos about file and generic data formats from Wotsit.org.
2 foundamental steps:
Recognize image format (gif, png, jpeg, ...). This can be done by file extension, if image files are "trustable" or in some other kind of way.
Find image properties, that are specific image format informations, stored into processed file. You can find infos about file and generic data formats from Wotsit.org.
answered Apr 22 '13 at 15:22
Filippo LauriaFilippo Lauria
1,476816
1,476816
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16150434%2fshell-test-for-images-are-different%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown