this is the code with nested loop for pdf. How can i use pdf function here instead of loop?

It divides image into 2 subimage based on mean. How I use pdf function instead of loop to get
1) pdf1 from (1 <= mean) & for
2) pdf2 from (mean+1 > last value)
I = imread('f16.tif');
r=size(I,1);
c=size(I,2);
h1=uint8(zeros(r,c));
h2=uint8(zeros(r,c));
n1=r*c;
n2=r*c;
R=uint8(zeros(r,c));
f1=zeros(256,1);
f2=zeros(256,1);
pdf1=zeros(256,1);
pdf2=zeros(256,1);
cdf1=zeros(256,1);
cdf2=zeros(256,1);
cum1=zeros(256,1);
out1=zeros(256,1);
cum2=zeros(256,1);
out2=zeros(256,1);
Im=mean2(I);
I1=(I(r,c)<=Im);
I2=(I(r,c)>Im);
for i=1:r
for j=1:c
value1=I1(i,j);
f1(value1+1)=f1(value1+1)+1;
pdf1(value1+1)=f1(value1+1)/n1;
end
end
for i=1:r
for j=1:c
value2=I2(i,j);
f2(value2+1)=f2(value2+1)+1;
pdf2(value2+1)=f2(value2+1)/n2;
end
end

8 Comments

The code stops with an error in value1=I1(i,j); , because after I1=(I(r,c)<=Im); I1 is a scalar.
can i simply use pdf() function here instead of these loops?
this is a program for brightness preserving bi histogram equalization (BBHE) which firstly divides image into two subimages based on mean. then it calculates pdf & cdf for both subimages and at last add both subimage to one image
Again: The posted code does not run. Then it is impossible to decide, if another function creates the same output.
The description "divide an image into two subimages based on mean" is not unqiue. Then it is your turn either to provide running code or an exhaustive and clear definition of what you want to achieve. What exactly do you call "image"? The "mean" of what? What is a "subimage"? How do you "add subimages"?
X=image. Xm=mean of image,
Subimages[ Xl= values <= mean(Xm), Xu= values > mean(Xm)]
(pl & cl)= (PDF & CDF of values <=mean),
(pu & cu)= (PDF & CDF of values> mean) &
at last add both subimages(Xl+Xu) to get contrast enhanced image
It is getting less clear for me with every additional comment. You ignore my message, that the code you have posted does not run and my suggestion how to fix it. Just repeating your statements without answering my questions for clarifications does not allow to reconsider, what you are trying to do. I give up at this point.
this program divides histogram of an image into 2 sub-histograms based on the mean grayscale value and equalizing them separately.
I am beginner in matlab & I know that code is not working. I just wanted to know that how to run loop from (1 to mean value) to get pdf of 1st sub histogram & (mean+1 to last value) to get pdf of 2nd sub histogram or I can use simply pdf() to get both sub histograms
Im=mean2(I); % mean
I1=(I(r,c)<=Im); % values<= mean
I2=(I(r,c)>Im); % values > mean
% loop for pdf of values<= mean
for i=1:r
for j=1:c
value1=I1(i,j);
f1(value1+1)=f1(value1+1)+1;
pdf1(value1+1)=f1(value1+1)/n1;
end
end
% loop for pdf of values > mean
for i=1:r
for j=1:c
value2=I2(i,j);
f2(value2+1)=f2(value2+1)+1;
pdf2(value2+1)=f2(value2+1)/n2;
end
end
Did who get which code?
I still do not understand, what your question is.

Sign in to comment.

Answers (0)

Tags

Asked:

on 5 Feb 2021

Edited:

Jan
on 26 May 2021

Community Treasure Hunt

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

Start Hunting!