% [v] = histogram_streching_threshold(u,alpha,beta,th_a,v_a,th_b,v_b) % % This function performs a histogram streching by deviding the input values % into three regions and applying different strechings to each region. % Input parameters: % u -> Input luminance image with values 0-255 (uint8) % alpha -> slope first region % beta -> slope second region % th_a -> Threshold that separates region 1 and 2 % v_a -> output value for u=a % th_b -> Threshold that separates region 2 and 3 % v_b ->output value for u=b % Output: % v -> Enhanced imaged % % Programmed by Daniel Garcia-Romero 2-21-2006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [v] = histogram_streching_threshold(u,alpha,beta,th_a,th_b) [n_row,n_col]=size(u); v=zeros(n_row,n_col); u=double(u); MAX_LUM=255; % Set up the maximum value for Y MIN_U=min(min(u)); MAX_U=max(max(u)); v_o=-alpha*MIN_U; v_a=alpha*(th_a)+v_o; v_b=beta*(th_b-th_a)+v_a; gamma=(MAX_LUM-v_b)/(MAX_U-th_b); % This is not a free parameter for i=1:n_row for j=1:n_col if (u(i,j) < th_a) v(i,j)=alpha*(u(i,j))+v_o; elseif (u(i,j) >= th_a && u(i,j) < th_b ) v(i,j)=beta*(u(i,j)-th_a)+v_a; elseif (u(i,j) >= th_b && u(i,j) <= MAX_LUM ) v(i,j)=gamma*(u(i,j)-th_b)+v_b; else disp('ERROR: The input signal must take values between 0-255'); return; end end end v=uint8(v);