0
$\begingroup$

If I have an image whose range is from $-18.3667\cdot10^{-5}$ to $9.3127$, how could I normalize it on the same gradient so that they fall between a specific range, say fro $0$ to $255$?

$\endgroup$
  • 1
    $\begingroup$ That is really a question that you should be able to answer yourself with a sheet of paper, a pencil, and three lines of writing stuff down. $\endgroup$ – Marcus Müller Jan 7 '17 at 17:14
  • 1
    $\begingroup$ ...but if you need some sort of hint, you might want to take a look at this $\endgroup$ – A_A Jan 7 '17 at 20:02
1
$\begingroup$

First, shift: put the minimum to $0$, by compensating the actual minimum $m=−18.3667⋅10^5$ for every pixel: $p\to p - m$. Now your pixels are between $0$ and a new maximum $M = 9.3127 - m$. Finally you want the final image in $[0,255]$. The second operation is scale: multiply by something, so that $0$ remains at $0$, and $M$ is cast to $255$. So you have to multiply by $255/M$.

$\endgroup$
  • $\begingroup$ Thanks, I do it. [Sx, Sy]=size(T); % T the image that we want to normalize m=min(min(T)); M=max(max(T))- m; % shifting for i=1:Sx, for j=1:Sy, T(i,j)=T(i,j)-m; end end %Scaling T=T*255/M; $\endgroup$ – Achaire Jan 7 '17 at 20:30
  • $\begingroup$ All the operations are linear, so you can do this directly on the matrix, no loop: T = rand(3,3); Tnew = 255*(T-min(T(:)))/(max(T(:))-min(T(:))); $\endgroup$ – Laurent Duval Jan 7 '17 at 20:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.