how do i divide an image into odd and even images such that they are correlated and follow normal distribution?

5 ビュー (過去 30 日間)
i have written a short code of dividing image into odd and even sequences. but they have unequal means and std deviation, so they are uncorrelated. How do i correlate the odd and even sequences of the same image such that their means and covariance are same while they follow normal(gaussian distribution)?
a=imread('lena.jpg');
A=rgb2gray(a);
P1=im2double(A);
P=imresize(P1,[512 512]);
%figure(1);imshow(P);title('original image');
r=size(P1,1)
c=size(P1,2)
even=zeros(r,c);
odd=zeros(r,c);
ce=0;
co=0;
for i=1:r
for j=1:c
if (mod(a(i,j),2)==0)
even(i,j)=a(i,j);
ce=ce+1;
else
odd(i,j)=a(i,j);
co=co+1;
end
end
end
K = P1(:)
PD=fitdist(K,'normal')
Kodd=odd(:)
PDodd=fitdist(Kodd,'normal')
Keven=even(:)
PDeven=fitdist(Keven,'normal')

回答 (2 件)

harjeet singh
harjeet singh 2015 年 12 月 28 日
hello preeti if you are taking whole image and dividing that into even and off pixels, the values in even and odd pixels never be same so that the sigma always changes, it might be very close but i dont think it will be same, you may try this code if you initialize even matrix with zero's than at even places you are taking the pixel values from original image but at odd places it will be zero again.
a=imread('lena.jpg');
A=rgb2gray(a);
%P1=im2double(A);
P1=A;
P=imresize(P1,[512 512]);
figure(1);
imshow(P);
title('original image');
r=size(P1,1);
c=size(P1,2);
ce=0;
co=0;
even=[];
odd=[];
for i=1:r
for j=1:c
if (mod(a(i,j),2)==0)
even=[even a(i,j)];
ce=ce+1;
else
odd=[odd a(i,j)];
co=co+1;
end
end
end
K = P1(:);
PD=fitdist(K,'normal')
Kodd=odd(:);
PDodd=fitdist(Kodd,'normal')
Keven=even(:);
PDeven=fitdist(Keven,'normal')

Walter Roberson
Walter Roberson 2015 年 12 月 29 日
Optimization for your code:
even_mask = mod(a, 2) == 0;
even = a .* even_mask;
odd = a .* ~even_mask;
But now I want you to think about sum(even) and sum(odd). The sum of any number of even values is always even. The sum of any number of odd values is even if there are an even number of odd values, but is odd if there are an odd number of odd values. Can the two sums be the same? Clearly if there are an odd number of odd values, the two sums cannot be the same. Can their mean be the same anyhow? It is possible but the number of even values would have to be odd...
There are, in other words, reasons to expect that the mean of the odd values will not usually be the same as the mean of the even values.
(Note that in your implementation you count the number of even values and the number of odd values, but you do not total them and you do not divide the totals by the counts.)
If the question "are they derived from the same normal distribution" then expecting an exact match on their means or standard deviations should not be your test. Distributions are infinite and any finite subsample of an infinite distribution will have different statistics than the infinite distribution does. You should be considering something like kstest2()
Of course if you have uint8() values then you already know that the values cannot possibly be normally distributed: the normal distribution is two-tailed, infinite in both directions, so if your values are constrained to be non-negative there is no possible way a normal distribution could be the correct explanation. A Beta distribution could be the explanation though.

Community Treasure Hunt

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

Start Hunting!

Translated by