From: Rajesh Sarkar on
How can I compare two black & white images?
What are the properties(or functions) that can be taken for comparison?
e.g. if we take standard deviation of two images and then try to take the pecentage like (std2(image1)/std2(image2)*100), it will give some pecentage of matching. Is there any other function like std2? Please specify two or three functions for me.
I'm looking forward for your help.
Regards
Rajesh
Kolkata
From: Walter Roberson on
Rajesh Sarkar wrote:
> How can I compare two black & white images?

As I wrote in response to your nearly identical question earlier:

"There are an infinite number of functions that can be used for
comparison. [...]

Different comparison functions highlight different kind of properties.
The proper comparison function to use depends not on the image but on
the _intent_ of the comparison (and the available computation time)."

> What are the properties(or functions) that can be taken for comparison?
> e.g. if we take standard deviation of two images and then try to take
> the pecentage like (std2(image1)/std2(image2)*100), it will give some
> pecentage of matching. Is there any other function like std2? Please
> specify two or three functions for me. I'm looking forward for your help.

Image comparison algorithms of the sort you are looking for have the
following properties:
1) They must examine at least one property from each of the images; this
property can be information _about_ the image such as image size or data
class, or can be information contained within the image, such as one or
more pixels from the image;
2) They must make at least one mathematical or logical computation based
up; the computation need not even be fully deterministic
3) They must either directly calculate a percentage comparison, or else
provide an output number for each image that can be converted into a
percentage.

That's it. *Any* algorithm that has the above properties is an image
comparison algorithm. You could write 179 random lines of code that
happened to meet the above criteria, and if it manage to compile and
run, you would have an image comparison algorithm.

You may think I'm joking or being stupid or not answering the question,
but I am being serious: *anything* that provides some kind of
information about the properties or content of the images is (or can be
converted to) an image comparison algorithm.

If you think seriously about what I have written, you will see that the
important point is not _whether_ it is an image comparison algorithm,
but rather whether what it compares is of interest or utility for a
particular purpose. For most algorithms that qualify as image comparison
algorithms, you would be tempted to say "This is not an image comparison
algorithm!" or "This doesn't compute anything useful!", when you should
instead be saying, "I cannot think of any circumstance under which this
comparison would be useful" or "The circumstances under which this
comparison would be useful are so constrained that it is unlikely that
anyone would ever use this algorithm." This changes the emphasis from
whether or not the algorithm _is_ an image comparison algorithm, to a
matter of whether you can understand what it computes and imagine
circumstances under which it might be useful. The fact that you cannot
imagine a good use for a particular image comparison algorithm does not
mean that the algorithm is not still an image comparison algorithm.

If you are starting to understand that nearly *every* algorithms that
works on two matrices (generated or extracted from one or more files) is
an "image comparison algorithm", but that we have no *known* use for
most of what could potentially be computed, then you are getting the
right idea.

> What are the properties(or functions) that can be taken for comparison?
> e.g. if we take standard deviation of two images and then try to take
> the pecentage like (std2(image1)/std2(image2)*100), it will give some
> pecentage of matching.

I suspect that you do not have a clear understanding of what the uses
are of comparing std2 of two images. You say "it will give some
percentage of matching", but _what_ is it matching? It is *not*
"matching" the overall appearance of the images! Indeed, if you were to
take an image and sort the pixels values down the columns, the result
would have the same std2 (I think).

> Is there any other function like std2? Please
> specify two or three functions for me.

Think of several different attributes of an image that you might want to
compare. Now, what-ever algorithm is needed to compare one of those
attributes is an "image comparison" algorithm. Depending on what you
want to compare, the comparison algorithm might or might not have a
compact mathematical formula such as std2 (or you might not happen to
know of an existing mathematical notation under which the algorithm
becomes compact.)

When you are working with image comparison, you should always develop
the _intent_ of the comparison first, and only then work on selecting
algorithms that meet that intent as best possible. Starting with
functions such as std2() is the wrong way around. For example, consider:
in real life, do you start with the intent of tightening the hinges on
the cupboard and sort through your tools until you find something
appropriate -- or do you pick up a #2 Philips screwdriver and walk
around the house looking for things you can do with that particular
screwdriver? (Around a house, if you aren't rebuilding parts of the
house itself, chances are that you'll find more uses for a #1 Philips
than a #2 Philips....) Your asking about std2() is like asking about
what kind of screwdrivers are used in buildings, when you should instead
be asking what you want to build and then figure out what kind of saws
and drills and hammers and glue and screwdrivers and duct tape you will
need to build what you want.
From: Rajesh Sarkar on
Dear Sir
Thank you very much for your valuable ideas. Now I
am understanding that I am going into wrong direction
and putting worthless questions. But Sir, as I want to
compare two images - I want your advice that from where
I should start - like what are the aspects of a Black &
White image that can be compared? What are the different
inbuilt functions of MATLAB (just give some examples) that I
can take? Sir, I am very new in MATLAB and I'll be very
much grateful if you please help me.






Walter Roberson <roberson(a)hushmail.com> wrote in message <hqp4k3$5gh$1(a)canopus.cc.umanitoba.ca>...
> Rajesh Sarkar wrote:
> > How can I compare two black & white images?
>
> As I wrote in response to your nearly identical question earlier:
>
> "There are an infinite number of functions that can be used for
> comparison. [...]
>
> Different comparison functions highlight different kind of properties.
> The proper comparison function to use depends not on the image but on
> the _intent_ of the comparison (and the available computation time)."
>
> > What are the properties(or functions) that can be taken for comparison?
> > e.g. if we take standard deviation of two images and then try to take
> > the pecentage like (std2(image1)/std2(image2)*100), it will give some
> > pecentage of matching. Is there any other function like std2? Please
> > specify two or three functions for me. I'm looking forward for your help.
>
> Image comparison algorithms of the sort you are looking for have the
> following properties:
> 1) They must examine at least one property from each of the images; this
> property can be information _about_ the image such as image size or data
> class, or can be information contained within the image, such as one or
> more pixels from the image;
> 2) They must make at least one mathematical or logical computation based
> up; the computation need not even be fully deterministic
> 3) They must either directly calculate a percentage comparison, or else
> provide an output number for each image that can be converted into a
> percentage.
>
> That's it. *Any* algorithm that has the above properties is an image
> comparison algorithm. You could write 179 random lines of code that
> happened to meet the above criteria, and if it manage to compile and
> run, you would have an image comparison algorithm.
>
> You may think I'm joking or being stupid or not answering the question,
> but I am being serious: *anything* that provides some kind of
> information about the properties or content of the images is (or can be
> converted to) an image comparison algorithm.
>
> If you think seriously about what I have written, you will see that the
> important point is not _whether_ it is an image comparison algorithm,
> but rather whether what it compares is of interest or utility for a
> particular purpose. For most algorithms that qualify as image comparison
> algorithms, you would be tempted to say "This is not an image comparison
> algorithm!" or "This doesn't compute anything useful!", when you should
> instead be saying, "I cannot think of any circumstance under which this
> comparison would be useful" or "The circumstances under which this
> comparison would be useful are so constrained that it is unlikely that
> anyone would ever use this algorithm." This changes the emphasis from
> whether or not the algorithm _is_ an image comparison algorithm, to a
> matter of whether you can understand what it computes and imagine
> circumstances under which it might be useful. The fact that you cannot
> imagine a good use for a particular image comparison algorithm does not
> mean that the algorithm is not still an image comparison algorithm.
>
> If you are starting to understand that nearly *every* algorithms that
> works on two matrices (generated or extracted from one or more files) is
> an "image comparison algorithm", but that we have no *known* use for
> most of what could potentially be computed, then you are getting the
> right idea.
>
> > What are the properties(or functions) that can be taken for comparison?
> > e.g. if we take standard deviation of two images and then try to take
> > the pecentage like (std2(image1)/std2(image2)*100), it will give some
> > pecentage of matching.
>
> I suspect that you do not have a clear understanding of what the uses
> are of comparing std2 of two images. You say "it will give some
> percentage of matching", but _what_ is it matching? It is *not*
> "matching" the overall appearance of the images! Indeed, if you were to
> take an image and sort the pixels values down the columns, the result
> would have the same std2 (I think).
>
> > Is there any other function like std2? Please
> > specify two or three functions for me.
>
> Think of several different attributes of an image that you might want to
> compare. Now, what-ever algorithm is needed to compare one of those
> attributes is an "image comparison" algorithm. Depending on what you
> want to compare, the comparison algorithm might or might not have a
> compact mathematical formula such as std2 (or you might not happen to
> know of an existing mathematical notation under which the algorithm
> becomes compact.)
>
> When you are working with image comparison, you should always develop
> the _intent_ of the comparison first, and only then work on selecting
> algorithms that meet that intent as best possible. Starting with
> functions such as std2() is the wrong way around. For example, consider:
> in real life, do you start with the intent of tightening the hinges on
> the cupboard and sort through your tools until you find something
> appropriate -- or do you pick up a #2 Philips screwdriver and walk
> around the house looking for things you can do with that particular
> screwdriver? (Around a house, if you aren't rebuilding parts of the
> house itself, chances are that you'll find more uses for a #1 Philips
> than a #2 Philips....) Your asking about std2() is like asking about
> what kind of screwdrivers are used in buildings, when you should instead
> be asking what you want to build and then figure out what kind of saws
> and drills and hammers and glue and screwdrivers and duct tape you will
> need to build what you want.
From: Walter Roberson on
Rajesh Sarkar wrote:
> Dear Sir Thank you very much for your valuable ideas. Now I am
> understanding that I am going into wrong direction
> and putting worthless questions. But Sir, as I want to compare two
> images - I want your advice that from where
> I should start - like what are the aspects of a Black &
> White image that can be compared? What are the different
> inbuilt functions of MATLAB (just give some examples) that I can take?

Step (1) Create a list of inbuilt functions available in Matlab.

Step (2) Determine whether the remaining list of functions is empty.

Step (3) If the list was empty, you cannot complete your homework
assignment, so Stop; otherwise, continue.

Step (4) Choose a member of the list at random, and strike it off the
list for future consideration

Step (5) Determine whether the function is able to operate on at least
one 2D array and produce an answer that is at least partly deterministic
(under typical conditions) based upon either information _about_ the
array or information _in_ the array.

Step (6) If the function did not met the criteria of Step (5), then go
back to Step (2).

Step (7) Add the function to your list of examples

Step (8) Determine whether you have enough functions listed to satisfy
your homework assignment.

Step (9) If the answer to Step (8) was "not yet", then go back to Step (2).

Step (10) You have completed your homework assignment. Stop.


Remember what I wrote last posting: ANY function that analyzes anything
about an image or using the data in an image, and can have the result
transformed into a single number, is a function that meets the criteria
you gave for being an "image comparison" algorithm. Explaining the
circumstances under which any particular comparison might be useful is a
rather different matter that you did not ask about, and as new varieties
of images and new intents are being created every few minutes (speaking
world-wide), the fact that you cannot happen to think of a use for a
particular comparison does not mean that the comparison does not have
any meaningful uses -- it could even be the case that no-one had ever
thought to put the functions together that way before and that doing so
solves an important problem... or may solve a problem that will become
important 50 years from now.

Perhaps it might help if I name some functions which are NOT useful
image comparison algorithms:
- clear
- zeros()
- plot()
- error()
- computer()
- isdeployed()
- and sometimes rand().

rand() is not an image comparison algorithm *itself*, but rand() has
very important roles to play in a number of image comparison algorithms.


But I'll take pity on you and name a couple of specific functions to get
you started:

The two absolutely most important algorithms for image comparison are:
(A) "Subtract 1"; and
(B) "Compare to Zero"

with

(C) "Add 1" following quite closely behind in importance.

And no, this is not a joke: it is the basis of very fundamental theorems
in mathematics and science. Though one could make some serious arguments
that the single most important algorithm in computing is "Compare for
equality"... more fundamental theorems involved there.