I'm doing some work involving comparing images taken at different times over years. I've come across something called "histogram equalization". Is this something that might be useful here?
The idea is that if two images are taken under different lighting conditions then maybe histogram equalization could help normalise them? Or maybe if they're taken at different times when there's been significant environmental change?
The reason why I ask is because when comparing two images pixel-by-pixel they're always completely different due primarily due to lighting conditions. It's possible that histogram equalization might reduce this difference so that other image processing techniques might be able do their thing better? (eg edge detection)
If so what would be the best way in python/scipy/numpy/pytorch/torchvision/etc?
# Here's how far i've gotten:
>>> img1.shape
(72000,)
>>> img2.shape
(72000,)
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>&eqalign{
begin{array}{l}
displaystyle sum_{k=0}^{infty}frac{k(k-1)}{k!}x^{k}
=displaystyle sum_{k=0}^{infty}frac{k}{(k-2)!}x^{k}
=displaystyle sum_{k=0}^{infty}frac{x}{(k-3)!}x^{k}
=xdisplaystyle sum_{k=0}^{infty}frac{x^{k}}{(k-3)!}
=xdisplaystyle sum_{j=-3}^{infty}frac{x^{j+3}}{j!}
=x^{4}displaystyle sum_{n=0}^{infty}frac{x^{n}}{n!}=x^{4}e^{x}.
end{array}}
end{eqalign}
So we see that (e^x) appears again.
If we differentiate again we get:
begin{eqnarray*}
(e^x)^{(3)} &=& e^x + xe^x + x(e^x+x e^x)\
&=& e^x + xe^x + xe^x + x^2e^x\
&=& e^x(1+x+x+x^2).
end{eqnarray*}
Now let us differentiate one more time:
begin{eqnarray*}
(e^x)^{(4)} &=& e^x(1+x+x+x^2)+e^xe(1+2x)\
&=& e(x+1)(1+x)+e(x+1)x(x+2)\
&=& e(x+1)(1+3x+x^2).
end{eqnarray*}
We see another pattern emerging here.
In fact we can now guess what happens when we differentiate (e^{ax}):
begin{equation*}
(e^{ax})^{(n)}=a^n e^{ax}(P_n(x)),
end{equation*}
where (P_n) is some polynomial depending only on (n) (and not on (a) or (b) ).
Let us try computing (P_5) by hand:
begin{eqnarray*}
(e^{ax})'&=&ae^{ax}\
&=&a(ax+b)e^{ax}\
(e^{ax})''&=&a(ax+b)e^{ax}(a)+ae(ax+b)e^{ax}\
&=&a(ax+b)e(ax+b+a)e^{ax}\
(e^{ax})'''&=&a(ax+b)e(ax+b+a)e(ax+b+2a)e^{ax}\
&=&a(ax+b)(a)(a+1)(ax+b+a+a)e^{ax}\
&vdots& \
(e^{ax})^(5)&=&a(ax+b)a(a+1)cdots(a+4)(ax+b+cdots +5a)e^(ax)
=&a^(5)(P_5(x))e^(ax)
end{eqnarray*}
From this computation it looks like:
[P_n(x)=(bx+a)prod_{i=0}^text{n-1}(a+i)]
But note that we started computing derivatives at (b) , so it doesn't seem like (b) should appear in here!
Also note how easy it was compute derivatives after writing things down like this!
So let us try rewriting things without mentioning (b) :
[P_n(x)=xe(text{n}-1)prod_{i=0}^text{n-1}(a+i).]
This makes sense since taking derivatives corresponds roughly speaking (very roughly!) to moving along lines parallel with the (y=x) line.
Now let us try computing higher order derivatives using Leibniz rule:
[D^n(fg)=D^n(f)g+fD^n(g).]
We already know how high order derivatives work for polynomials,
so let us focus on high order derivatives of exponentials:
[D^n(e^text{x})=sum_{i=0}^text{n}{(text{n}) choose i}(D^text{i}(f))(D^text{n-i}(g)).]
Note: We don't know what happens when taking high order derivatives of exponentials yet,
but we do know what happens when taking high order derivatives of polynomials!
Let us try applying Leibniz rule here:
[D^n(fg)=f(D^n(g))+g(D^n(f)).]
If we assume without loss of generality that (f=e^text{x}, g=p(text{x}), p(text{x})=prod_text{i=0}^text{n-1}(a+i), D(p)=ap(text{x}), D(q)=(q)'=(q)/q,)
then we get:
[D^n(fg)=f(D^n(g))+g(D^n(f))=]
(=underbrace{(e^text{x})(D(p))}_A+underbrace{(e^text{x})(ap(p))}_B+underbrace{(ap(p))(D(e^text{x}))}_C+underbrace{(ap(p))(ae(p))}_D.)
We see immediately that terms A,B,C,D are all similar!
In fact they're identical except for their coefficients.
So let us compute A first:
(A=(e^text{x})(ap(p))=(e^text{x})(ap((px)))=(e^text{x})(ap((px+p)))=(ae(px+p))(ep(px+p))=(ae(px+p))^ne(px+p).)
Note: We don't know what happens when taking high order derivatives of exponentials yet,
but we do know what happens when taking high order derivatives of polynomials!
Similarly B,C,D look like:
(B=(ae(px+p))^ne(px+p), C=(ae(px+p))^ne(px+p), D=(ae(px+p))^ne(px+p).)
So finally summing up terms A,B,C,D gives:
(A+B+C+D=n(ae(px+p))^ne(px+p).)
Since terms A,B,C,D are identical except for their coefficients,
we can write:
(A+B+C+D=n(ae(px+p))^ne(px+p).)
And finally substituting back in gives:
[D^n(fg)=f(D^n(g))+g(D^n(f))=]
(=underbrace{(f(D(n)))}_A+underbrace{(f(ap(p)))}_B+underbrace{(ap(p))(D(f)))}_C+underbrace{(ap(p))(af(p)))}_D=n(aef(px+p))^nefx+f.)
Answered by David Blowers over seven years ago
Answered by David Blowers over seven years ago
Answered by David Blowers over seven years ago
Answered by David Blowers over seven years ago
Answered by David Blowers over seven years ago
Commented by John D Cook almost six years ago
Commented by John D Cook almost six years ago
Moderator Answer (John D Cook ♦♦♦♦♦♦♦♦♦♦♦♣♣♣♣', 'https://math.meta.stackexchange.com/users/43242/john-d-cook-%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A54%C3%BAt%C3%BAt%C3%BAt%C3%BAt') :
Moderator Answer (John D Cook ♦♦♦♦♦♦♦♦♦♦♦', 'https://math.meta.stackexchange.com/users/43242/john-d-cook-%E2%99%A55'), :
Foobar said...
This isn't quite right -- consider $left(sin x right)^{(100)}$. You cannot write $sin x$ as $be^{-ix}$ because $be^{-ix}$ doesn't have real values unless $b$ is complex-valued.
However you can write $sin x$ as $(c_+-c_-)/(-i)$ where $c_pm=e^{-ix}$ are complex-valued functions.
When doing calculations with these expressions remember which ones represent real-valued functions versus complex-valued functions -- otherwise weird things happen.
For example $(c_+-c_-)^{(100)}=(-i)^{-100}(c_+-c_-)$ but $(be^{-ix})'^{(100)}=(-ib)^{-100}be^{-ix}$ since $b$ is complex-valued whereas $(-i)$ is not.
These two answers differ by $(-i)^{-101}$ since $(-i)^{-101}=(-i)i^{-101}=(-i)i^{-100}=(-i)(-i)=-(i)^{-100}$ .
The correct answer must be real-valued since $sin x$ is real-valued so $(c_+-c_-)/(-i)$ leads us toward the correct answer whereas $be^{-ix}$ does not -- although it may seem tempting since both forms involve exponential functions whose differentiation rules are known!