i am writing the matlab code for bi-histogram equalization for the color image...i am using the 'function' to extend to all three planes i.e, RG&B ...but i am getting error 'Function definitions are not permitted in this context.'.

2 次查看(过去 30 天)
clc;
close all;
clear all;
function y = BBHE(x);
sz = size(x);
o_mean = round(mean(x(:)));
% HISTOGRAM
h_l = zeros(256,1);
h_u = zeros(256,1);
for i = 1:sz(1)
for j = 1:sz(2)
g_val = x(i,j);
if(g_val<=o_mean)
h_l(g_val+1) = h_l(g_val+1) + 1;
else
h_u(g_val+1) = h_u(g_val+1) + 1;
end
end
end
disp(h_l)
disp(h_u)
nh_l = zeros(256,1);
nh_u = zeros(256,1);
% NORMALIZED HISTOGRAM OR PDF
nh_l = h_l/sum(h_l);
nh_u = h_u/sum(h_u);
% % CDF
hist_l_cdf = double(zeros(256,1));
hist_u_cdf = double(zeros(256,1));
hist_l_cdf(1) = nh_l(1);
hist_u_cdf(1) = nh_u(1);
for k = 2:256
hist_l_cdf(k) = hist_l_cdf(k-1) + nh_l(k);
hist_u_cdf(k) = hist_u_cdf(k-1) + nh_u(k);
end
% IMAGE REMAPPING
equalized_img = zeros(sz);
range_l = [0 o_mean];
range_u = [(o_mean+1) 255];
for i =1:sz(1)
for j =1:sz(2)
g_val = x(i,j);
if(g_val<=o_mean)
equalized_img(i,j) = range_l(1) + round(((range_l(2)-range_l(1))*hist_l_cdf(g_val+1)));
else
equalized_img(i,j) = range_u(1) + round(((range_u(2)-range_u(1))*hist_u_cdf(g_val+1)));
end
end
end
the above code is in one .m file and following code is in another .m file
a = imread('C:\Users\Public\Pictures\Sample Pictures\imageo1.jpg');
x = a(:,:,1);
y = BBHE(x);
figure,imshow(y);

采纳的回答

Image Analyst
Image Analyst 2014-2-5
Get rid of the
clc;
close all;
clear all;
and get rid of the semicolon after
function y = BBHE(x);
replace y with equalized_img:
function equalized_img = BBHE(x)
and it should work fine. I did (with a standard color demo image) and it worked fine.
  2 个评论
vishwas h s
vishwas h s 2014-2-5
thanks for the solution sir....but now i am getting a new kind of error saying that "Output argument "equalized_image" (and maybe others) not assigned during call to "C:\Users\vishwas\Documents\MATLAB\BBHE.m>BBHE".
Image Analyst
Image Analyst 2014-2-5
Just step through the code and find out why you're not stepping into the for loops. Like I said, I used it with peppers.png and it worked fine.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by