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

조회 수: 1 (최근 30일)
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]);

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 12월 6일
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
NIKHIL SINGH
NIKHIL SINGH 2020년 7월 23일
can u share the final code which gave the output after making changes
Saphsa Codling
Saphsa Codling 2020년 7월 23일
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]);

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by