How do i vectorize an image?

9 Ansichten (letzte 30 Tage)
Prashanna Jain
Prashanna Jain am 14 Okt. 2015
Kommentiert: Walter Roberson am 15 Okt. 2015
I am trying to break a square matrix of an image and create another vector which contains its column vector sub-blocks. I used the following code for it and getting an error
for i=1:50 a(i)=A(:,i)
The error says 'In an assignment A(I) = B, the number of elements in B and I must be the same.'
Please help me how i can solve my problem.
  9 Kommentare
Prashanna Jain
Prashanna Jain am 15 Okt. 2015
i want to write an algorithm to find the KL Transform of the image, for which i need to vectorize the image to find the mean and covariance. converting it to grayscale and double will lead to loss in data..so i might have to use the coloured version.
Walter Roberson
Walter Roberson am 15 Okt. 2015
mean(Array) gives a vector of column means, you do not need to split it up. Likewise with std()

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Walter Roberson
Walter Roberson am 14 Okt. 2015
a = mat2cell(A, size(A,1), ones(1,size(A,2)));
Now a{K} will be the column vector corresponding to A(:,K)
  2 Kommentare
Walter Roberson
Walter Roberson am 14 Okt. 2015
For RGB one solution would be
a = mat2cell(A, size(A,1), ones(1,size(A,2)), size(A,3));
This would create a{k} as being an N x 3 matrix, rather than creating the vectors that were asked for. Or you could use
a = mat2cell(A, size(A,1), ones(1,size(A,2)), ones(1,size(A,3)));
which would create a as an N x 3 cell array, each entry of which is a column vector.
Prashanna Jain
Prashanna Jain am 15 Okt. 2015
but this is easy to implement for a 3x3 matrix..i will have to apply it on an image of about 100x100..writing it for the entire thing would be tedious no?

Melden Sie sich an, um zu kommentieren.


Thorsten
Thorsten am 14 Okt. 2015
Bearbeitet: Thorsten am 14 Okt. 2015
Why don't you just get your vectors from A using
A(:,i);
I can see no reason why a you need to re-organize your data.
  2 Kommentare
Prashanna Jain
Prashanna Jain am 15 Okt. 2015
i did try a(i)=A(:,i); under a for loop..it gave an error as mentioned in my problem above
Prashanna Jain
Prashanna Jain am 15 Okt. 2015
also this will only work on a 2D image..what do i do for an rgb one?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by