Question: Request edge to be cropped (1. top, 2. left, 3. right, 4. bottom), and number of pixels to开发者_如何学编程 remove and does it. Implement as a function: pic_new = crop_image(pic,direction,pixels);
How do I go about making a function with the indicated inputs? I know there is a function called imcrop() but I can't seem to get it to work. Please help. Thank you for your time.
But imcrop
is the exact function you need to use. In your case, it should be like this:
First, construct a rectangle by coordinates and it's height and width:
x = 50
y = 50
height = 20
width = 20
Then, load and crop the image:
I = imread('image.png');
I2 = imcrop(I, [x, y, height, width]);
imshow(I), figure, imshow(I2)
You begin a function definition like this:
function [out1, out2] = my_func(in1, in2, in3)
You can handle a range of behaviours based on the value of variable like this:
switch (x)
case 1
% Stuff for x==1
case 2
% Stuff for x==2
case 3
% Stuff for x==3
otherwise
% Stuff for all other values of x
end
You can remove elements from an array like this:
matrix_out = matrix_in(x1:x2, y1:y2, :);
(Remember that an image is usually represented as a 2D array (or 3D if it's RGB).
This should be enough to answer your question. If it's not, you need to be more clear about what you want to do.
精彩评论