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

16 visualizzazioni (ultimi 30 giorni)
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]);

Risposta accettata

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH il 6 Dic 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 Commenti
Saphsa Codling
Saphsa Codling il 23 Lug 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]);

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by