how to get odd rows and columns,even rows and columns

25 vues (au cours des 30 derniers jours)
juveria fatima
juveria fatima le 13 Mar 2018
Commenté : Birdman le 14 Mar 2018
A1 is the lena image
A is to the first row
similarly how to get the even rows ,even columns,odd rows,odd columns
A1 = imread('lena1.jpg');
A=A1(:,1);
  3 commentaires
Birdman
Birdman le 13 Mar 2018
No need for loops again:
A1(1:end,:)
juveria fatima
juveria fatima le 14 Mar 2018
i want to store all the rows one by one
i am finding the probability of each row one by one similarly each column one by one
(sum of probabilities should be one)
here is my code
%A = randi(255, [1 10]);
% A = imread('lena1.jpg');
A1 = imread('lena1.jpg');
A=A1(:,1);
A = reshape(uint8(A), [1 512*1]);
s = size(A);
[rows columns numberOfColorBands] = size(A);
col1 = 1;
col2 = floor(columns/2);
col3 = col2 + 1;
row1 = 1;
row2 = floor(rows/2);
row3 = row2 + 1;
% Now crop
upperLeft = imcrop(A, [col1 row1 col2 row2])
count = zeros(1,256);
for i =1:s(1)
for j =1:s(2)
count(uint8(A(i,j)+1)) = count(uint8(A(i,j)+1))+1;
end
end
count = double(count) /(512*1);
sumofprob=sum((count))
plot(count)

Connectez-vous pour commenter.

Réponse acceptée

Birdman
Birdman le 13 Mar 2018
Consider you have number of rows and columns which is an even number,
Odd rows:
A1(1:2:end-1,:)
Even rows:
A1(2:2:end,:)
Odd columns:
A1(:,1:2:end-1)
Even columns:
A1(:,2:2:end)
  3 commentaires
Jos (10584)
Jos (10584) le 14 Mar 2018
By substracting one, you discard the last odd row (column) when the number of rows (columns) of the array is odd. When this number is even, it does not matter, so just to be flexible, do not subtract one :)
Birdman
Birdman le 14 Mar 2018
Yes you are right Jos, therefore at the beginning of the question, I stated that:
Consider you have number of rows and columns which is an even number
:)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by