Crop a 1m * 1m image along a 60 ° line, with a cutting area of 0.1m * 0.1m rectangle, for a total of 100 images
Show older comments
% 导入BMP图像
img = imread('your_image.bmp');
% 原始图像尺寸
original_height = size(img, 1); % 图像高度
original_width = size(img, 2); % 图像宽度
% 生成底角线上的点
x0 = linspace(0, original_width, 100); % 在底部生成100个点
y0 = linspace(0, original_height, 100); % 在左侧生成100个点
% 60°线方程 y = tan(60°) * x
tan_60_deg = tan(deg2rad(60)); % 将角度转换为弧度
y_line = tan_60_deg * x0;
% 裁剪图片
crop_size = [0.1*original_height, 0.1*original_width]; % 裁剪尺寸
for i = 1:100
x_coord = round(x0(i)); % 取整数坐标
y_coord = round(y_line(i));
% 检查裁剪区域是否越界
if x_coord + crop_size(2) > original_width || y_coord + crop_size(1) > original_height
continue; % 越界则跳过
end
% 裁剪图片
cropped_img = img(y_coord:y_coord+crop_size(1)-1, x_coord:x_coord+crop_size(2)-1, :);
% 保存裁剪后的图片
imwrite(cropped_img, sprintf('cropped_image_%d.bmp', i));
end
Starting from the bottom of the photo, draw a line where a point on the line is a vertex of the rectangular box, but I cannot achieve it
Thank you for your answers.
My email is 1803905353@qq.com

Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!