Board logo
Elargir le spectre d'une image .pgm

ftbass - 11/07/2004 à 02:48

code:

function GetIntensiteMax(Matrice : in TypeMatrice) return integer is

Resultat : integer := 0;
i, j : integer := 0;

begin
while (i <= Matrice'Last(1)) and (j <= Matrice'Last(2)) and (Resultat /= 255) loop
if character'pos(Matrice(i, j)) > Resultat then
Resultat := character'pos(Matrice(i, j));
end if;
if j = 255 and i < 255 then
j := 0;
i := i + 1;
else
j := j + 1;
end if;
end loop;

return Resultat;


end GetIntensiteMax;

-- Fonction qui retourne l'intensité min des pixels d'une image
function GetIntensiteMin(Matrice : in TypeMatrice) return integer is

Resultat : integer := 255;
i, j : integer := 0;

begin
while (i <= Matrice'Last(1)) and (j <= Matrice'Last(2)) and (Resultat /= 0) loop
if character'pos(Matrice(i, j)) < Resultat then
Resultat := character'pos(Matrice(i, j));
end if;
if j = 255 and i < 255 then
j := 0;
i := i + 1;
else
j := j + 1;
end if;
end loop;

return Resultat;

end GetIntensiteMin;



-- Fonction qui étend le spectre à 0..255
function ElargirSpectre(MatriceI : in typeMatrice) return TypeMatrice is

Resultat : TypeMatrice(MatriceI'range(1), MatriceI'range(2));

Max, Min : Integer;
Coeff : Float;

begin
  -- Détermination du max de l'image originale
  Max := GetIntensiteMax(MatriceI);
  -- Détermination de son min
  Min := GetIntensiteMin(MatriceI);
  -- Détemination du Coeff
  Coeff := 255.0 / (Float(Max) - Float(Min));
  for i in MatriceI'range(1) loop
     for j in MatriceI'range(2) loop
        Resultat(i, j) := character'val(Integer((Float(character'pos(MatriceI(i, j))) - Float(Min)) * Coeff));
     end loop;
  end loop;
 
  return Resultat;
 
end ElargirSpectre;