generating matrix randomly
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Junaid
2012-1-3
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.
0 个评论
更多回答(1 个)
Junaid
2012-1-3
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 个评论
Walter Roberson
2012-1-3
I wouldn't expect any of them to have good clarity compared with the original image.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!