function nl_srgb=gama_korekce(rgb, gama)
%Úprava gama korekce a filtrace umu pozadí snímku
nl_srgb = rgb.^(gama); %1/2.2 je  standratní gama korekce

loc= nl_srgb>1;
nl_srgb(loc)=1;
loc= nl_srgb<0;
nl_srgb(loc)=0;
R=nl_srgb(:,:,1); G=nl_srgb(:,:,2); B=nl_srgb(:,:,3);
[~,loc]=findpeaks(imhist(R),'SortStr','descend','NPeaks',2,'MINPEAKHEIGHT', 10000,'MINPEAKDISTANCE',26);
if size(loc)==1
    loc=[1 loc];
end
y=imhist(R);
[~,x]=min(y(min(loc):max(loc)));
pom=(min(loc)+x-2)/256;
loc= R<pom;
R(loc)=0;

[~,loc]=findpeaks(imhist(G),'SortStr','descend','NPeaks',2,'MINPEAKHEIGHT', 10000,'MINPEAKDISTANCE',12);
if size(loc)==1
    loc=[1 loc];
end
y=imhist(G);
[~,x]=min(y(min(loc):max(loc)));
pom=(min(loc)+x-2)/256;
loc= G<pom;
G(loc)=0;

[~,loc]=findpeaks(imhist(B),'SortStr','descend','NPeaks',2,'MINPEAKHEIGHT', 10000,'MINPEAKDISTANCE',12);
if size(loc)==1
    loc=[1 loc];
end
y=imhist(B);
[~,x]=min(y(min(loc):max(loc)));
pom=(min(loc)+x-2)/256;
loc= B<pom;
B(loc)=0;
nl_srgb=cat(3,R,G,B);
