generating matrix randomly

I have an matrix of an image ,face.jpg,now i want to interchange the pixel values,position of values must be changed( randomly),,please help

 채택된 답변

Junaid
Junaid 2012년 1월 3일

2 개 추천

Dear What I understand is you will randomly swap the pixel values of images 6 times. At the end you will have 6 images. Again multiple ways to do it. Here is one example.
myface = imread('myface.jpg'); % this is your image
myface1 = myface; % just to keep the copy of original
for i=1:6 % this decides how many times you want to repeat
myRan = randperm(prod(size(myface))); % we assume myface.jpg is grayscale
myRan=reshape(myRan,size(myface));
myface(myRan) = myface;
myimageset{i} = myface;
myface = myface1;
end
Now you have six images in myimageset. You can get image by myimageset like this.
image1 = myimageset{1};
you can put myimageset in loop and display each image to see your output. The code I have written is not optimal. The computation speed can be improved. I did this way to divide the process into step so that you can follow what actually is happening.

추가 답변 (1개)

Junaid
Junaid 2012년 1월 3일

1 개 추천

There are many ways to do it. One possible way is.
myface = imread('myface.jpg');
myRan = randperm(prod(size(myface))); % we assume myface.jpg is grayscale
myRan=reshape(myRan,size(myface));
myface(myRan) = myface;
These four lines can be done in one line. Just to show you the steps i followed this into four lines.

댓글 수: 7

kash
kash 2012년 1월 3일
thank u juniard ,how to read the image from those final pixels
kash
kash 2012년 1월 3일
Juniard like this i need 6 matrices ,where the pixels are intercganged
Walter Roberson
Walter Roberson 2012년 1월 3일
You would need to know the myRan permutation vector in order to reverse the transformation. This is known as the Key Exchange Problem, http://en.wikipedia.org/wiki/Key_exchange#The_key_exchange_problem
kash
kash 2012년 1월 3일
Thanks walter i went through it ,i ment i need to read the image from those final pixels,the may may contain whatever it may,like these i want to generate 6 marices and check which matrix values give as near as the original image
Walter Roberson
Walter Roberson 2012년 1월 3일
I am having trouble figuring out what you are trying to do, sorry.
kash
kash 2012년 1월 3일
Walter here are the steps
1.need to take an image
2.need to interchange the coefficient (randomly) 6 times
3.now i get 6 matrices (no 2 coefficient must be same)
4.from this i need to get 6 images
5.finally need to check which has good clarity compared with original image
Walter Roberson
Walter Roberson 2012년 1월 3일
I wouldn't expect any of them to have good clarity compared with the original image.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2012년 1월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by