divImg2 - out2 = imarr(:,c./2+1:end,:); u = 'false'; v =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function [out1 out2 u v] = divImg2(imarr,md) %Given an image array, write a function divImg that will divide the %image into halves or quadrants. %The second input can only be one of three things: %'lr' You should create a left and right half of the image. Store the %left half as the first output, the right half as the second output, %and false for the third and fourth outputs. %'tb' You should create a top and bottom half of the image. Store the %top half as the first output, the bottom half as the second output, %and false for the third and fourth outputs. %'q' You should divide the image into 4 pieces. The top left quadrant %is the first output, the top right is the second, the bottom left %is the third, and the bottom right is the fourth. %Constraints: %In the case of an odd number of pixels, you should round up after %dividing by two. [r c clr] = size(imarr); switch md case 'lr' if mod(c,2)==0 out1 = imarr(:,1:c./2,:);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: out2 = imarr(:,c./2+1:end,:); u = 'false'; v = 'false'; else ncols = ceil(c./2); out1 = imarr(:,1:ncols,:); out2 = imarr(:,ncols+1:end,:); u = 'false'; v = 'false'; end case 'tb' if mod(r,2)==0 out1 = imarr(1:r./2,:,:); out2 = imarr(r./2+1:end,:,:); u = 'false'; v = 'false'; else nrows = ceil(r./2); out1 = imarr(1:nrows,:,:); out2 = imarr(nrows+1,:,:); u = 'false'; v = 'false'; end case 'q' if mod(r,2)==0 top = imarr(1:r./2,:,:); bottom = imarr(r./2+1,:,:); else nrows = ceil(r./2); top = imarr(1:nrows,:,:); bottom = imarr(nrows+1,:,:); end if mod(c,2)==0 left = imarr(:,1:c./2,:); right = imarr(:,c./2+1:end,:); else ncols = ceil(c./2); left = imarr(:,1:ncols,:); right = imarr(:,ncols+1:end,:); end [r2 c2] = size(left); [r3 c3] = size(right); out1 = top(:,1:c2,:); out2 = top(:,c3:end,:); u = bottom(:,1:c2,:); v = bottom(:,c3:end,:); end end...
View Full Document

Page1 / 2

divImg2 - out2 = imarr(:,c./2+1:end,:); u = 'false'; v =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online