this is the code with nested loop for pdf. How can i use pdf function here instead of loop?
Show older comments
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
Jan
on 5 Feb 2021
See also your other question: https://www.mathworks.com/matlabcentral/answers/736892-how-to-create-nested-loop-for-following-equation#comment_1309417
The code stops with an error in value1=I1(i,j); , because after I1=(I(r,c)<=Im); I1 is a scalar.
Jagdeep S
on 6 Feb 2021
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"?
Jagdeep S
on 7 Feb 2021
Jan
on 7 Feb 2021
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.
Aswini B
on 26 May 2021
did you get the code?
Jan
on 26 May 2021
Did who get which code?
I still do not understand, what your question is.
Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
