algorithm - a program to apply the following transformation function to a grayscale image -
i want apply following transformation function grayscale image, know how apply following function,

my question how apply program following transformation function,

code far,
clear; pollen = imread('fig3.10(b).jpg'); u = double(pollen); [nx ny] = size(u) nshades = 256; r1 = 80; s1 = 10; % transformation piecewise linear function. r2 = 140; s2 = 245; = 1:nx j = 1:ny if (u(i,j)< r1) uspread(i,j) = ((s1-0)/(r1-0))*u(i,j) end if ((u(i,j)>=r1) & (u(i,j)<= r2)) uspread(i,j) = ((s2 - s1)/(r2 - r1))*(u(i,j) - r1)+ s1; end if (u(i,j)>r2) uspread(i,j) = ((255 - s2)/(255 - r2))*(u(i,j) - r2) + s2; end end end hist= zeros(nshades,1); i=1:nx j=1:ny 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'); thanks in advance
the figure says intensities between a , b, should set c. have modify 2 for loops values between a , b, set output location c. i'll assume range inclusive. can remove first , last if conditions , use middle one:
for = 1:nx j = 1:ny if ((u(i,j)>=r1) && (u(i,j)<= r2)) uspread(i,j) = c; end end end c constant set yourself. segmentation, result high distinguish foreground background. have uint8 image here, c = 255; work.
however, recommend achieve more vectorized solution. avoid for loops , use logical indexing instead:
uspread = u; uspread(u >= r1 & u <= r2) = c;
Comments
Post a Comment