title: a program to apply the following transformation function to a grayscale image
body: <p>I want to apply following transformation function to a grayscale image, i know how to apply it to the following function,</p>
  
  <p><img src="https://i.stack.imgur.com/oEh97.png" alt="transformation function"></p>
  
  <p>my question is how do i apply a program to the following transformation function,</p>
  
  <p><img src="https://i.stack.imgur.com/BAtEP.png" alt="what i wanted to be done"></p>
  
  <p>code so far,</p>
  
  <pre><code>clear;
  pollen = imread('Fig3.10(b).jpg');
  u = double(pollen);
  [nx ny] = size(u)
  nshades = 256;
  r1 = 80; s1 = 10; % Transformation by piecewise linear function.
  r2 = 140; s2 = 245;
  for i = 1:nx
   for j = 1:ny
   if (u(i,j)&lt; r1)
   uspread(i,j) = ((s1-0)/(r1-0))*u(i,j)
   end
   if ((u(i,j)&gt;=r1) &amp; (u(i,j)&lt;= r2))
   uspread(i,j) = ((s2 - s1)/(r2 - r1))*(u(i,j) - r1)+ s1;
   end
   if (u(i,j)&gt;r2)
   uspread(i,j) = ((255 - s2)/(255 - r2))*(u(i,j) - r2) + s2;
   end
   end
  end
  hist= zeros(nshades,1);
  for i=1:nx
   for j=1:ny
   for k=0:nshades-1
   if uspread(i,j)==k
   hist(k+1)=hist(k+1)+1;
   end
   end
   end
  end
  plot(hist);
  pollenspreadmat = uint8(uspread);
  imwrite(pollenspreadmat, 'pollenspread.jpg'); 
  </code></pre>
  
  <p>Thanks in advance </p>