chee
chee

Reputation: 979

how to get some portion from an image in matlab?

i have an image I of size 512x256. i want to get some portion like a slice from this image I. like i want I1 of size 512x50 .

Upvotes: 3

Views: 5851

Answers (2)

YYC
YYC

Reputation: 1802

x = [1:50]; % define the scope of x-axis (the "columns") for the portion of the image
y = [1:512]; %define the scope of y-axis (the "rows") for the portion of the image

I1 = I(x,y,:); % Create I1, the desired portion of the image. Assuming the original image is of RGB and you need to access all 3 colors. 

Upvotes: 1

Jonas
Jonas

Reputation: 74930

To take a slice that includes the first 50 columns, and all rows, do the following

sliceOfImage = originalImage(:,1:50)

To take a slice that includes columns 100 to 149, call

sliceOfImage = originalImage(:,100:149)

etc.

Upvotes: 2

Related Questions