Azzera filtri
Azzera filtri

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.'.

4 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Image Analyst
Image Analyst il 5 Feb 2014
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 Commenti
vishwas h s
vishwas h s il 5 Feb 2014
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 il 5 Feb 2014
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by