knn compare 2 images matlab [duplicate] - matlab

This question already has answers here:
Image comparison - fast algorithm
(12 answers)
Image similarity comparison
(7 answers)
Closed 5 years ago.
I need a help. I don't know how to write a Matlab/Java code compare 2 images using KNN, the result should take "wrong" when image 2 is different than image 1. I have to imporve displacement between x1,x2,x3 and that each subsequent generated image with the same x1,x2,x3 is invalid (Prove that the diameter has increased). Others compare it with histograms. Anybody will help me?

Related

Swift random element with probability [duplicate]

This question already has answers here:
Generate random numbers with a given distribution
(4 answers)
how to generate random numbers from 1 to 4 and 8 in swift
(2 answers)
Closed 4 months ago.
It seems like randomElement() in Swift only allows for an equally weighted selection. What would be the best (and most efficient way, as I need to repeat this very often) to select from a collection with pre-specified probabilities/weights?

name matrix as A1 to A50 automatically [duplicate]

This question already has answers here:
Create variables with names from strings
(6 answers)
How to Dynamically Create Variables in MATLAB [duplicate]
(3 answers)
Closed 5 years ago.
I run an algorithm that result of it is a matrix as A. I run an algorithm 50 times and I want to save results as A1 to A50 matrix. how can I write?

MATLAB: fast creation of vector of indices [duplicate]

This question already has answers here:
Run-length decoding in MATLAB
(4 answers)
Closed 6 years ago.
I have a variable distr=[0 3 1 0 2];, and I have a variable full which should contrain distr(i) times i, for all i.
In this example, i want:
full=[2 2 2 3 5 5];
because distr(2)=3, therefore 3x 2, and so on.
Of course I can do it in a for-loop:
full=zeros([1,sum(distr)]);
cc=1;
for i=1:length(distr)
curr=distr(i);
full(cc:cc+curr-1)=i*ones([1,curr]);
cc=cc+curr;
end
but that is very slow. Do you know of a fast way, using MATLAB's awesome array-oriented style? Thanks!
Not sure, but maybe this will work. I can't check it since I currently don't have MATLAB:
full_tmp = arrayfun(#(i,n) i*ones(1,n),1:length(distr),distr,'uniformoutput',false);
full = cat(2,full_tmp{:});

MATLAB: How to randomize the rows of a matrix? [duplicate]

This question already has answers here:
Random order of rows Matlab
(4 answers)
Closed 7 years ago.
I'm looking for an efficient way to manipulate a 40x151 matrix so that the rows are randomly scrambled.
I worked out the answer just as I was about to post.
new_matrix = old_matrix(randperm(40),:)

how to rearrange each block into a column vector? [duplicate]

This question already has answers here:
Efficient Implementation of `im2col` and `col2im`
(2 answers)
Closed 7 years ago.
example: I have an image,it's size 512X512pixel,then i have splited it into 8x8 blocks.Now i would have 64x64 blocks.Now how to rearrange each block 8x8 into column vector so that the dimension would be 64x4096pixel without inbuilt function "im2col".please help me out.
Thanks.
x=rand(512,512);
xi=mat2cell(x,8*ones(1,64),8*ones(1,64));
xii=cellfun(#(x)reshape(x,1,64),xi,'UniformOutput',false);
y=cell2mat(xii);