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 件のコメント

Jan
Jan 2021 年 2 月 5 日
What have you tried so far?
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 5 日
I think, you can avoid nested loop here.
Jagdeep S
Jagdeep S 2021 年 2 月 5 日
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 2021 年 2 月 5 日
編集済み: Jan 2021 年 2 月 5 日
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?
Jagdeep S
Jagdeep S 2021 年 2 月 6 日
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
Jan
Jan 2021 年 2 月 6 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2021 年 2 月 5 日

コメント済み:

Jan
2021 年 2 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by