MATLAB: Hi all… i am writing a program to histogram equalize particular bit planes in an image..but i am getting an error in the 1st bit plane..Attempted to access a(241,320); index out of bounds because size(a)=[240,320]. Error in BITPLANE (line 59)

bit planeindex out of bounds

clc;
close all;
clear all;
a = imread('F:\TEST PICTURES\car.jpg');
a = rgb2gray(a);
[m n] = size(a);
% to extract 7th bit plane
for i = 1:m
for j = 1:n
b7(i,j) = bitand(a(i,j),128);
end
end
b7o = histeq(b7);
%to extract 6th bit plane
for i = 1:m
for j = 1:n
b6(i,j) = bitand(a(i,j),64);
end
end
b6o = histeq(b6);
%to extract 5th bit plane
for i = 1:m
for j = 1:n
b5(i,j) = bitand(a(i,j),32);
end
end
b5o = histeq(b5);
%to extract 4th bit plane
for i = 1:m
for j = 1:n
b4(i,j) = bitand(a(i,j),16);
end
end
b4o = histeq(b4);
%to extract 3rd bit plane
for i = 1:m
for j = 1:n
b3(i,j) = bitand(a(i,j),8);
end
end
b3o = histeq(b3);
%to extract 2nd bit plane
for i = 1:m
for j = 1:n
b2(i,j) = bitand(a(i,j),4);
end
end
b2o = histeq(b2);
%to extract 1st bit plane
for i = 1:m
for i = 1:n
b1(i,j) = bitand(a(i,j),2);
end
end
b1o = histeq(b1);
%to extract 0th bit plane
for i = 1:m
for j = 1:n
b0(i,j) = bitand(a(i,j),1);
end
end
b0o = histeq(b0);
cc = 2*(2*(2*(2*(2*(2*(2*b7o+b6o)+b5o)+b4o)+b3o)+b2o)+b1o)+b0o;
figure, imshow(cc)

Best Answer

You miscoded
for i = 1:n
instead of
for j = 1:n
Related Question