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

Hiren Parmar
Hiren Parmar 2015년 10월 14일
편집: Hiren Parmar 2015년 10월 14일
A = imread('cameraman.tif'); % your image
a = A(:); % Image matrix is converted to column vector.
Prashanna Jain
Prashanna Jain 2015년 10월 14일
thankyou for the input but i'm not trying to make a single vector. I'm trying to convert my NxN image into N column vectors, each of those vector have columns from the NxN image. i hope you get my point.
Is the image an RGB image, or indexed or grayscale? If the image is RGB then is has size M*N*3. Can you please tell us exactly the output of
size(A); % A is your image
Varun Pai
Varun Pai 2015년 10월 14일
Then that will be same as your original NxN image. Can you please show your requirement by using a 3 x 3 matrix as an example ?
Prashanna Jain
Prashanna Jain 2015년 10월 14일
if A is a 3x3 matrix with elements [1,2,3,; 4,5,6,; 7,8,9] then i want to create a vector B such that its first element has [1,4,7], second has [2,5,8], and third has [3,6,9]
Prashanna Jain
Prashanna Jain 2015년 10월 14일
Stephen Cobeldick : how do i proceed if i want to do the same for an RGB image?
Stephen23
Stephen23 2015년 10월 14일
편집: Stephen23 2015년 10월 14일
@Prashanna Jain: the answer depends on you. Each pixel of an RGB image is made up of the R, G and B values, so do you want to keep these values together (with each column that you are splitting the image into), or do you want to split each column of the image into three separate variables (one for each of R, G and B).
In the first case you will get a matrix of some kind, in the second case you get three vectors. Which do you want?
It is probably a lots easier to not split your data up anyway. Why do you need to split the image into vectors? Why not just use indexing and access the parts that you need to?
Prashanna Jain
Prashanna Jain 2015년 10월 15일
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 2015년 10월 15일
mean(Array) gives a vector of column means, you do not need to split it up. Likewise with std()

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

답변 (2개)

Walter Roberson
Walter Roberson 2015년 10월 14일

0 개 추천

a = mat2cell(A, size(A,1), ones(1,size(A,2)));
Now a{K} will be the column vector corresponding to A(:,K)

댓글 수: 2

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 2015년 10월 15일
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?

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

Thorsten
Thorsten 2015년 10월 14일
편집: Thorsten 2015년 10월 14일

0 개 추천

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

Prashanna Jain
Prashanna Jain 2015년 10월 15일
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 2015년 10월 15일
also this will only work on a 2D image..what do i do for an rgb one?

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

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

질문:

2015년 10월 14일

댓글:

2015년 10월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by