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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
1 commentaire
CSE
le 26 Mar 2014
please help me if you have run this code on color images..my code is not working on color images.please send me suggestion for code on manjeetg9@gmail.com.
Réponse acceptée
Image Analyst
le 5 Fév 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 commentaires
Image Analyst
le 5 Fév 2014
Do you know how to use the debugger? http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!