resizeImage - Þtermines if the number is a percentage a =...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function reimarr = resizeImage(imarr,nw,nh) %Write a function resizeImage that will use the round(linspace()) method %of resizing to resize an image. The new width and height may be input %in one of three ways: %- As a double representing the new size in pixels (50) %- As a string representing the new size in pixels ('42') %- As a string representing a percentage of the old size ('50%') %Thus, if you have an image that is 240x320, the following are valid %methods of resizing it to 420x240: %newimg = resizeImage(img,420,'240'); %newimg = resizeImage('200%',240); %newimg = resizeImage('200%','75%'); %Hint: %If you write a helper function that deals with your width, you can %reuse it for your height and save yourself some code. [r c clr] = size(imarr); if ischar(nw) %determines whether the new width is a string if strcmp(nw(end),'%')
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %determines if the number is a percentage a = str2num(nw(1:end-1)); %converts the actual numbers of the string into double num = (a./100).*c; %figures out the correct number of columns if the input is a %percent else num = str2num(nw); %if not a percent, then convert to double end else num = nw; %if double, then keep end if ischar(nh) if strcmp(nh(end),'%') b = str2num(nh(1:end-1)); num2 = (b./100).*r; else num2 = str2num(nh); end else num2 = nh; end %lines 34 - 43 do the same operations with the new height (which %corresponds to the rows of the image array rind = round(linspace(1,r,num2)); cind = round(linspace(1,c,num)); %lines 46 - 47 determine the new dimensions of the output reimarr = imarr(rind,cind,:); %indexes into the original array with the new dimensions...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern