0

I'm trying to implement vlsh with the California ND Dataset, which is composed by 701 photos. 10 subject wrote down in a txt file which photos are near duplicate for them, and we have also correlation matrix. The images are RGB and I reduced them in 20x20. I created a 4-d array 20x20x3x701. So I tried to reshape and obtained a 1200x701 matrix, but the problem is that reshape can't maintain the order of the original matrix. I tried to search online and most of suggestion is to use "Permute", but it seems to me that doesn't fit my situation.

I can post the MATLAB code:

path='C:\Users\franc\Desktop\stage\californiaND\prova*.jpg';
path2='C:\Users\franc\Desktop\stage\californiaND\prova';
d=dir(path);
a=[];
for m=1:length(d)
  a=cat(4,a,imread(strcat(path2,d(m).name)));
end
r=reshape(a,[],701);
r=double(r);
L = lshConstruct( r, 10,4);
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • 1
    What is the order you'd want your data to be with respect to the input? – BillBokeey Aug 23 '17 at 10:15
  • I want that every matrix of the same image is concatenated. So one matrix of 1200 pixel, for 701 images. – FireFox1616 Aug 23 '17 at 10:21
  • Yes, but in what order should the 2nd and 3rd dimensions be collapsed into the 1st dimension? Reshape doesn't randomise the order... – Wolfie Aug 23 '17 at 11:19
  • It looks like the problem is that you crate a 4D matrix.... just create what you want from the start, not from the 4D matrix – Ander Biguri Aug 23 '17 at 11:24
  • @AnderBiguri How can i do it? i have 2-d matrix in 3 channel. I have to reshape anyway, or at least i think. Can you help me? thank you anyway – FireFox1616 Aug 23 '17 at 11:29
  • So whats the order of the data in each 1D image? RGBRGBRGB or RRRR....GGGGG....BBBB? – Ander Biguri Aug 23 '17 at 11:31
  • @AnderBiguri The order should be RGBRGBRGB – FireFox1616 Aug 23 '17 at 13:17
  • @Wolfie Sorry maybe i can't express myself correctly. Let's say 2 images 2x2 RGB. ` Image1: 1 2| 5 6 |9 10 3 4| 7 8 |11 12 image2: 13 14|17 18|21 22 15 16|19 20|23 24 I need something like that: 1 2 5 6 9 10 3 4 7 8 11 12 13 14 17 18 21 22 15 16 19 20 23 24 or 1 2 13 14 3 4 15 16 5 6 17 18 7 8 19 20 9 10 21 22 11 12 23 24.` I simply want that images information stay the same so i can give them to the lsh. I think that the problem is the reshape, don't know what else i'm doing wrong. – FireFox1616 Aug 23 '17 at 13:23

1 Answers1

0

I am assuming you need the 1D vector in RGBRGB format, as otherwise the solution would be trivial ( just (:)).

Assuming imread is reading 20x20x3 images one by one, this is how you directly make your 2D matrix:

for m=1:length(d) % this is 701, right?
  im=imread(strcat(path2,d(m).name));
  im=permute(im,[3 1 2]);
  a=cat(2,im(:));
end
Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • That's quite what i want, really thank you. I'll try to explain when i apply your method to 2 x 2 x3 images instead of a 20 x 20 x 3. iim2(:,:,1) = 113 85 108 81 iim2(:,:,2) = 100 72 95 68 iim2(:,:,3) = 107 79 102 75 This is the last image i get when i execute the code. If i could get this: 113 108 85 81 100 95 72 68 107 102 79 75 i think i've solved my problem. Instead i got this: 113 100 107 108 95 102 85 72 79 81 68 75. – FireFox1616 Aug 23 '17 at 13:58
  • 1
    For that, just do `iim2(:)` instead of the `permute`. But that's RRRBBBGGG. –  Aug 23 '17 at 14:13
  • @FireFox1616 yes, what Jon says. Consider accepting the answer as valid – Ander Biguri Aug 23 '17 at 14:21
  • Thank you a lot to both of you. Now lsh algorithm finally works. Really Thank you – FireFox1616 Aug 23 '17 at 17:53