I reshaped the image elements 256*256 into 16*1 linear array using the following code. There is 16 linear arrays in a variable (ex:tv). Now i need to retrieve the first array of variable (tv). ie, i need tv(1), tv(2)... tv(16). Please say the code.

I=imread('cameraman.tif'); I=double(I); Im=size(I); %find the size of the image [nr nc nd]=size(I); % Divide into blocks disp(nr); disp(nc);
% Divide into blocks m=64; n=64; row=1; column=1; i=1; j=1; sum=0; count=0; nnn=1; er1=0; for i=1:4:16
for j=1:4:16
block=I(i:i+3,j:j+3);
disp(block)
T = rand(16,16); % Size of all your vectors, concatenated
Tr = reshape(T,[4,4,16])
%convert 4X4 into 16X1 column vector
tv=reshape(block,16,1);
disp(tv)
count=count+1
column=column+4;
end
row=row+4;
end

Réponses (1)

I didn't delve into your code but I see you creating a 16x1 vector in it:
tv=reshape(block,16,1);
so what's the problem?

4 commentaires

thank you sir for your reply. there are 16 vectors in the form of 16*1. now i want to access all vectors separately.. for ex, tv=reshape(block,16,1); tv has 16 vectors in the form of 16*1.i need to access tv(1),tv(2),... tv(16). please send code.. i am very new to matlab. please help me.
Just make it a 2D array with indexing
tv = zeros(16, length(1:4:16)); % One column for each possible value of j
column = 1;
for j=1:4:16
% Code......
tv(:, column) = reshape(T,[4,4,16]);
column = column + 1;
% more code....
end
Now each one of those tv you have will be saved into one column instead of being overwritten during the next iteration.
thank you sir for your reply again. i used your code. but i am having the following error sir. please guide me. because i am very new to matlab. sorry for the disturbance. please answer me sir. the error is: ??? Error using ==> reshape To RESHAPE the number of elements must not change.
Error in ==> array4 at 11 tv(:, column) = reshape(I,[4,4,16]);
thank you sir. your answer is correct. i am so happy.. thank you so much sir.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Vehicle Dynamics Blockset dans Centre d'aide et File Exchange

Question posée :

le 19 Fév 2016

Commenté :

le 21 Fév 2016

Community Treasure Hunt

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

Start Hunting!

Translated by