Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part II: Local Histogram Statistics Download the image tungsten.tif. Reproduce t

ID: 1846419 • Letter: P

Question

Part II: Local Histogram Statistics Download the image tungsten.tif. Reproduce the results in figure 3.27, p. 143. Repeat the process for the enhanced image obtained using local histogram statistics (image c) in part 1 with a 5x5 neighborhood Display a scaled version of the difference image between image c in parts 1 and 2. Comment on the results. Part III: Image Smoothing Download the image test_pattem.tif. Filter the image using a square averaging filter of size 7x7 and symmetric padding. Display the filtered image in part 1. Repeat steps 1 and 2 with filter of size 19x19. Comments on the results.

Explanation / Answer

%answer 3

A=imread('FigP4.1(a)(test_pattern).tif');
figure
imshow(A);
%WINDOW SIZEv 7x7
N=7;
h = fspecial('average', N);
F=imfilter(B,h,'symmetric');
figure
imshow(F);


%WINDOW SIZEv 19x19

N=19;
h = fspecial('average', N);
F=imfilter(B,h,'symmetric');
figure
imshow(F);


%answer 2

A=imread('FigP3.4(a)(embedded_objects_noisy).tif'); %replace by second question tif image and not the screenshot since screenshot is not greyscale image
close all;
imhist(A);
figure
imshow(A);
B=histeq(A);
figure
imshow(B);
Img=A;
Img1=A;

%WINDOW SIZEv 3x3
M=3;
N=3;
mid_val=round((M*N)/2);
PadM=1;
PadN=1;
%PADDING THE IMAGE WITH ZERO ON ALL SIDES
B=padarray(A,[PadM,PadN]);

for i= 1:size(B,1)-((PadM*2)+1)
   
    for j=1:size(B,2)-((PadN*2)+1)
        cdf=zeros(256,1);
        inc=1;
        for x=1:M
            for y=1:N
%FIND THE MIDDLE ELEMENT IN THE WINDOW         
                if(inc==mid_val)
                    ele=B(i+x-1,j+y-1)+1;
                end
                    pos=B(i+x-1,j+y-1)+1;
                    cdf(pos)=cdf(pos)+1;
                   inc=inc+1;
            end
        end
                     
        %COMPUTE THE CDF FOR THE VALUES IN THE WINDOW
        for l=2:256
            cdf(l)=cdf(l)+cdf(l-1);
        end
            Img(i,j)=round(cdf(ele)/(M*N)*255);
     end
end
figure
imshow(Img);
%%%%%%%%%%%%%%%%%%%%%%%%%window size 7x7         %%%%%%%%%%%%%
%WINDOW SIZE
M=7;
N=7;
mid_val=round((M*N)/2);
PadM=3;
PadN=3;
%PADDING THE IMAGE WITH ZERO ON ALL SIDES
B=padarray(A,[PadM,PadN]);

for i= 1:size(B,1)-((PadM*2)+1)
   
    for j=1:size(B,2)-((PadN*2)+1)
        cdf=zeros(256,1);
        inc=1;
        for x=1:M
            for y=1:N
%FIND THE MIDDLE ELEMENT IN THE WINDOW         
                if(inc==mid_val)
                    ele=B(i+x-1,j+y-1)+1;
                end
                    pos=B(i+x-1,j+y-1)+1;
                    cdf(pos)=cdf(pos)+1;
                   inc=inc+1;
            end
        end
                     
        %COMPUTE THE CDF FOR THE VALUES IN THE WINDOW
        for l=2:256
            cdf(l)=cdf(l)+cdf(l-1);
        end
            Img(i,j)=round(cdf(ele)/(M*N)*255);
     end
end
figure
imshow(Img);

%WINDOW SIZE
M=5;
N=5;
mid_val=round((M*N)/2);
PadM=2;
PadN=2;
%PADDING THE IMAGE WITH ZERO ON ALL SIDES
B=padarray(A,[PadM,PadN]);

for i= 1:size(B,1)-((PadM*2)+1)
   
    for j=1:size(B,2)-((PadN*2)+1)
        cdf=zeros(256,1);
        inc=1;
        for x=1:M
            for y=1:N
%FIND THE MIDDLE ELEMENT IN THE WINDOW         
                if(inc==mid_val)
                    ele=B(i+x-1,j+y-1)+1;
                end
                    pos=B(i+x-1,j+y-1)+1;
                    cdf(pos)=cdf(pos)+1;
                   inc=inc+1;
            end
        end
                     
        %COMPUTE THE CDF FOR THE VALUES IN THE WINDOW
        for l=2:256
            cdf(l)=cdf(l)+cdf(l-1);
        end
            Img1(i,j)=round(cdf(ele)/(M*N)*255);
     end
end
figure
imshow(Img1);
diffrence_img=uint8(Img1-Img);
histeq(diffrence_img);