How to create nested loop for following equation?

It divides image into 2 subimage based on mean. How I enter values in nested loop for first PDF(Pl) from (1 <= mean) & for second PDF(Pu) from (mean+1 > last value)

6 Commenti

What have you tried so far?
I think, you can avoid nested loop here.
this is the code with nested loop for pdf. how can i use pdf function here instead of loop?
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
Jan
Jan il 5 Feb 2021
Modificato: Jan il 5 Feb 2021
Your code does not run.
I1=(I(r,c)<=Im);
I2=(I(r,c)>Im);
Now I1 and I2 are scalars. Then:
for i=1:r
for j=1:c
value1=I1(i,j);
must fail.
Do you mean:
I1 = (I <= Im);
I2 = (I > Im);
Why do you allocate 256 elements for f1 and f2, although you fill only the first two elements?
Are you sure, that the code does, what you expect?
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
You have posted several questions about the same problem. I've mentioned, that your code does not run at all and answered your comment above in one of your other threads already.
Please focus on one thread. Explain your problem uniquely and answer questions for clarifications. This will increase your chance to get a useful answer and avoids that posting an answer is a waste of time. Thanks.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Tag

Richiesto:

il 5 Feb 2021

Commentato:

Jan
il 6 Feb 2021

Community Treasure Hunt

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

Start Hunting!

Translated by