开发者

Syntax error for rectangular image

开发者 https://www.devze.com 2023-02-17 20:19 出处:网络
There is an image X of N*M size row M,column N. There are other 2 images A,B of sam开发者_Python百科e size as X. The objective is to shuffle the rows of X with the rows extracted from A and shuffle th

There is an image X of N*M size row M,column N. There are other 2 images A,B of sam开发者_Python百科e size as X. The objective is to shuffle the rows of X with the rows extracted from A and shuffle the columns of X with the columns extracted from B resulting in a totally modified img.

I am stuck at the point where simultaneously this is occuring. I am aware about the colon operator with which the code runs but for a square image. Please help how to go about it.

X=imread('picture.jpg');
[r c]=size(X);
[dummy,rowscrambleIdx]=sort(A,1);
X_shuffled=X;
[dummy,colscrambleIdx]=sort(B,2);

EDIT: The following code works for square image and I want to do similar operation for a rectangular sized image. However, this code does not work for rectangular sized image. I have tried to make the first code follow a similar logic but it does not work for a non-square RGB image having say 256*240*3 size

    X=imread('picture.jpg');

    [dummy,scrambleIdx]=sort(A(:));
    X_shuffled=X;
    X_shuffled(:)=A(scrambleIdx);

%now unscrambling
[dummy,unscrambleIdx] = sort(scrambleIdx);
X_recovered=X;
X_recovered(:)=X_shuffled(unscrambleIdx);


Why not use randi to randomly create some number of indicies to pull from A, and some to pull from B?

Example:

m=10;
n=5;
A=rand(m,n)
B=ones(m,n)

%3x1 vector of random ints b/w 1 and 10
index=randi([1 10],3,1);

rand_row = A(index,:);
B(index,:)=rand_row

Then output is:

index =

    10
     9
     4

A =

0.9797    0.1174    0.7303    0.6241    0.2619
0.4389    0.2967    0.4886    0.6791    0.3354
0.1111    0.3188    0.5785    0.3955    0.6797
0.2581    0.4242    0.2373    0.3674    0.1366
0.4087    0.5079    0.4588    0.9880    0.7212
0.5949    0.0855    0.9631    0.0377    0.1068
0.2622    0.2625    0.5468    0.8852    0.6538
0.6028    0.8010    0.5211    0.9133    0.4942
0.7112    0.0292    0.2316    0.7962    0.7791
0.2217    0.9289    0.4889    0.0987    0.7150


B =

     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1


B =

    1.0000    1.0000    1.0000    1.0000    1.0000
    1.0000    1.0000    1.0000    1.0000    1.0000
    1.0000    1.0000    1.0000    1.0000    1.0000
    0.2581    0.4242    0.2373    0.3674    0.1366
    1.0000    1.0000    1.0000    1.0000    1.0000
    1.0000    1.0000    1.0000    1.0000    1.0000
    1.0000    1.0000    1.0000    1.0000    1.0000
    1.0000    1.0000    1.0000    1.0000    1.0000
    0.7112    0.0292    0.2316    0.7962    0.7791
    0.2217    0.9289    0.4889    0.0987    0.7150
0

精彩评论

暂无评论...
验证码 换一张
取 消