How can you extract odd and even rows and columns from image to seperate image outputs

16 visualizaciones (últimos 30 días)
Hi there. I might be overthinking this. I often do but I'm trying to take the odd columns and rows and then even rows and columns from an image and then output them to form two seperate images in a subplot, with the original image maintained. I am confused at how I handle the additional dimension and I think this might be causing the output to fail. Any advice would be much appreciated. Code below.
%Load image
function [RowsEven, ColsEven]=oddevenpic(A);
A=imread('brain.jpg');
sizeofarray=size(A);
B=zeros(sizeofarray(1), sizeofarray(2));
C=zeros(sizeofarray(1), sizeofarray(2));
image(B);
image(C);
for r=1:sizeofarray(1);
for c=1:sizeofarray(2);
for RowsEven=mod(A,r)==0;
for ColsEven=mod(A,c)==0;
if (A(r)==RowsEven) | (A(c)==ColsEven);
(B(r)==RowsEven) & (B(c)==ColsEven);
else
(C(r)==(A(r)~=RowsEven)) & (C(c)==(A(c)~=ColsEven));
end
end
end
end
end
% %Display
subplot(3,2,3);
imshow(A);
title('Original Image')
%
subplot(3,2,2);
imshow(B);
title('Even Pixels Only')
%
subplot(3,2,1);
imshow(C)
title('Odd Pixels Only')
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]);

Respuesta aceptada

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH el 6 de Dic. de 2019
B=A(2:2:size(A,1),2:2:size(A,2),:);%Even Pixels Only
C=A(1:2:size(A,1),1:2:size(A,2),:);%Odd Pixels Only
  3 comentarios
NIKHIL SINGH
NIKHIL SINGH el 23 de Jul. de 2020
can u share the final code which gave the output after making changes
Saphsa Codling
Saphsa Codling el 23 de Jul. de 2020
Sure Nikhil
%A script to load an image, export all odd columns and rows to output B,
%and all even columns and rows to output C.
%Load image
A=imread('brain.jpg');
%obtain odd and even columns and rows from image A and output to images B
%and C
B=A(2:2:size(A,1),2:2:size(A,2),:);%Even Columns and Rows Only
C=A(1:2:size(A,1),1:2:size(A,2),:);%Odd Rows and Columns Only
% Display subplot 1, all in colour
figure
s(1)=subplot (2,1,1);
imshow(A);
title('(A) Original Image')
%
s(1)=subplot (2,2,3);
imshow(B);
title('(B) Even Columns and Rows Only')
% %
s(1)=subplot (2,2,4);
imshow(C)
title('(C) Odd Columns and Rows only')
%maximise size in subplot 1
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0, 1, 1]);

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by