1 / 5

Image Processing in MatLab

CS100: Into to Computer Science. Image Processing in MatLab. MatLab is a powerful tool to manipulate graphics and images. Prepared by Fred Annexstein University of Cincinnati Some Rights Reserved. WORKING WITH IMAGES in MatLab. Basic Image functions: Reading: img1=imread('image1.jpg');

kioko
Download Presentation

Image Processing in MatLab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS100: Into to Computer Science Image Processing in MatLab MatLab is a powerful tool to manipulate graphics and images Prepared by Fred Annexstein University of Cincinnati Some Rights Reserved

  2. WORKING WITH IMAGES in MatLab Basic Image functions: Reading: img1=imread('image1.jpg'); Writing: imwrite(img1, 'image2.jpg'); Displaying: imshow(img1); Recall that Last time we did an Exercise: Find 2 images online and add them together. You only needed to crop them to the same size.

  3. WORKING WITH IMAGES in MatLab RESIZING >> img=imread(‘my.jpg'); >> [rows, cols, colors]= size(img) % Increase the number of rows >> stretchfactor = 1.5 >> rowVec= linspace(1,rows,stretchfactor*rows); >> newrows=round(rowVec); % Decrease number of columns >> stretchfactor = 0.75; >> colVec= linspace(1,cols,stretchfactor*cols); >> newcols=round(colVec); >> newimag=img(newrows,:,:) >> imshow(newimg); >> newimag=newimg(:,newcols,:) >>imshow(newimg)

  4. WORKING WITH IMAGES in MatLab • Color Masking • Sometimes we want to replace pixels of an image of one or more colors with pixels from another image. It is useful to use a “blue screen” in some instances. • Find an image with a big plot of one color. First we will replace that color. And then we will find another image for pixel replacement. • Let us plot the color values of one chosen row…This will tell us the pixel values of the color we want to replace. • v = imread(‘myimg.jpg’) • image(v) • row= input(‘which row?’); • red = v(row,:,1); • green = v(row,:,2); • blue = v(row,:,3); • plot(red,’r’); • hold on • plot(green,’g’); • plot(blue,’b’);

  5. WORKING WITH IMAGES in MatLab • Suppose we want to replace those values whose intensities exceed a threshold value of 160 in each color. • v= imread(‘myimg.jpg’); • thresh= 160 • layer = (v(:,:,1) > thresh) & (v(:,:,2) > thresh) (v(:,:,2) > thresh) • mask(:,:,1) = layer; • mask(:,:,2) = layer; • mask(:,:,3) = layer; • If you want to only mask a portion of the image you can use something like… • >> mask(700:end,:,:)= false; • Which sets the mask so that we do not affect rows 700 and above • To reset the color to red • >>newv = v; • >>newv(mask)(1) = 255 • Or to replace pixels from a different image w use…>> newv(mask) = w(mask); • Let us try to do this with a blue screen…..

More Related