필터 지우기
필터 지우기

switching pixel with defined colour in a matrix

조회 수: 1 (최근 30일)
Gemma
Gemma 2014년 11월 17일
답변: Image Analyst 2014년 11월 18일
Hello everybody,
I would like to shuffle single pixels (or even better: groups of pixels) of an image. Important is that every pixel keeps its colour information, so that in the end, the values of pixels of one certain colour is constant.
I know how to do that with a normal matrix. But when it is about colour-values, I have 3 linked matrices (in the RGB-colour-range). How is it possible to combine the 3 matrices with the same grade of permutation?
Or is it possible to select the n-th permutation of a matrix and reshaping it? is that n-th permutation of matrix a in the same way permuted like the n-th permutation of matrix b?
I hope I made myself clear and that somebody could help.
Thank you in advance

채택된 답변

Evan
Evan 2014년 11월 17일
편집: Evan 2014년 11월 17일
If I is your image:
I = imread('peppers.png');
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
Idx = reshape(randperm(numel(R)),size(R));
R = R(Idx); G = G(Idx); B = B(Idx);
I_new = cat(3,R,G,B);
% Visualize the images.
subplot(1,2,1); imagesc(I); title('Before'); axis image
subplot(1,2,2); imagesc(I_new); title('After'); axis image
% Test to see that pixels have only been re-ordered, not changed.
sum(I(:)) == sum(I_new(:))
Also, it looks like there are some tools on the file exchange that allow you to "scramble" images in more sophisticated ways:
  댓글 수: 2
Gemma
Gemma 2014년 11월 17일
Hello Evan,
That's awesome! =) Until now I played around and got this:
I = imread('3mal3.png'); imshow(I)
R = I(:,:,1) G = I(:,:,2) B = I(:,:,3)
% permutation R perm_R = perms(R(:)) subset_R = perm_R(4, :) nteMatrix_R = reshape(subset_R,3,3) % permutation G perm_G = perms(G(:)) subset_G = perm_G(4, :) nteMatrix_G = reshape(subset_G,3,3) % permutation B perm_B = perms(B(:)) subset_B = perm_B(4, :) nteMatrix_B = reshape(subset_B,3,3)
%% Wieder zu RGB zusammensetzen nteMatrix_R=R nteMatrix_G=G nteMatrix_B=B
At that moment when I was trying to combine my RGB-values in one image again, you answered! And your skript is very much better, because mine needs so much time for running! Thank you very much! :)
Evan
Evan 2014년 11월 17일
No problem. Glad it's working for you!

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 11월 18일
For whatever it's worth (now that you've accepted a working example), I attach my demo (below the image it creates). (I was traveling the last two days and I didn't see this until now.)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by