Saturday 31 August 2013

8 bit Slicing

8-BIT SLICING
A = imread('a.bmp');
[row,col] = size(A);
count = zeros(256);
s = zeros(256);
bit_plane0 = rand(row,col);
bit_plane1 = rand(row,col);
bit_plane2 = rand(row,col);
bit_plane3 = rand(row,col);
bit_plane4 = rand(row,col);
bit_plane5 = rand(row,col);
bit_plane6 = rand(row,col);
bit_plane7 = rand(row,col);
for i=1:row
    for j=1:col
        count(A(i,j)+1) = count(A(i,j)+1) + 1;
    end
end
for i=1:256
    count(i) = count(i) / (row*col);
end
for k=1:256
    for i=1:k
        s(k) = s(k) + count(i);
    end
    s(k) = s(k) * 255;
end
for i=1:row
    for j=1:col
        A(i,j) = s(A(i,j)+1);
    end
end
for x=1:row
    for y=1:col
        bit_plane0(x,y)=bitand(A(x,y),2^(0));
    end
end

for x=1:row
    for y=1:col
        bit_plane1(x,y)=bitand(A(x,y),2^(1));
    end
end
for x=1:row
    for y=1:col
        bit_plane2(x,y)=bitand(A(x,y),2^(2));
    end
end

for x=1:row
    for y=1:col
        bit_plane3(x,y)=bitand(A(x,y),2^(3));
    end
end

for x=1:row
    for y=1:col
        bit_plane4(x,y)=bitand(A(x,y),2^(4));
    end
end

for x=1:row
    for y=1:col
        bit_plane5(x,y)=bitand(A(x,y),2^(5));
    end
end

for x=1:row
    for y=1:col
        bit_plane6(x,y)=bitand(A(x,y),2^(6));
    end
end

for x=1:row
    for y=1:col
        bit_plane7(x,y)=bitand(A(x,y),2^(7));
    end
end


imwrite(bit_plane0,'1.bmp','bmp');
imwrite(bit_plane1,'2.bmp','bmp');
imwrite(bit_plane2,'3.bmp','bmp');
imwrite(bit_plane3,'4.bmp','bmp');
imwrite(bit_plane4,'5.bmp','bmp');
imwrite(bit_plane5,'6.bmp','bmp');
imwrite(bit_plane6,'7.bmp','bmp');

imwrite(bit_plane7,'8.bmp','bmp');

No comments:

Post a Comment