by:黄光耀
% %%%%%%%%%%%画网格%%%%%%%%%%
% %%%%%%%%%%把带瓶盖的托盘完全分割开%%%%%%%%%
% close all
% clc
% clear
% %% 读入图像.
% imgmilk = imread(’.\标记\1.jpg’);
% %% 旋转
% angle = 0; %手动调整
% imgmilkh = imrotate(imgmilk,angle);
% %% 剪裁 % impixelinfo帮助确定位置信息和灰度信息(上、下、右、)
% rect = [0,0,2051,1911];
% imgmilkobj=imcrop(imgmilkh,rect);
% figure,imshow(imgmilkobj),title(‘目标’);
% imwrite(imgmilkobj,’.\demo-出图\1.jpg’);
% %% 画网格,画出行和列
% % 定义一个24位图
% imgmilkobj_color(:,:,1)=imgmilkobj;
% imgmilkobj_color(:,:,2)=imgmilkobj;
% imgmilkobj_color(:,:,3)=imgmilkobj;
% figure,imshow(imgmilkobj_color),title(‘原图的24位截图’);
% imwrite(imgmilkobj_color,‘10.jpg’);
% % 读入一个图片,对其网格进行划分;
% A=imread(‘10.jpg’);
% % [m,n]=size(A);
% % b=ones(m,n,3);
% b(:,:,1)=A(:,:,1);
% b(:,:,2)=A(:,:,2);
% b(:,:,3)=A(:,:,3);
% %%%%%%%%%%%%参数设置%%%%%%%%%%%%
% m=1; %左上角起点坐标
% n=1;
% % height=1880; % 上下,,矩形区域的长宽(这是适用于15-16中)
% % width=2040;%左右,,矩形区域的长宽(这是适用于15-16中)
%
% height=1800; % 上下,,矩形区域的长宽(这是适用于103_1-103_3,103_2,103_4中);
% width=1920;%左右,,矩形区域的长宽(这是适用于103_1-103_3,103_2,103_4中);
% colpar1=255;
% colpar2=0;
% colpar3=0;
% [b,p]=darwline(b,m,n,height,width,colpar1,colpar2,colpar3);
% figure,imshow(uint8§);
% %figure,imshow(uint8(b));.
% % img_grid是代网格的图片
% img_grid= uint8§;
% % figure;
% % imshow(img_grid);
% % title(‘原始图像’)
% %%这是定义M个行、N个列,
% M=9;
% N=11;
% imshow(img_grid);
% title(‘网格demo-出图图像’, ‘FontWeight’, ‘Bold’);
% hold on;
% [xt, yt] = meshgrid(round(linspace(1, size(img_grid, 1), M)), …
% round(linspace(1, size(img_grid, 2), N)));%生成数据点矩阵
% mesh(yt, xt, zeros(size(xt)), ‘FaceColor’, …
% ‘None’, ‘LineWidth’, 1, …
% ‘EdgeColor’, ‘r’);%绘制三维网格图
% % 确定是否有瓶盖
% % end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%画网格%%%%%%%%%%%%%
% %% 画网格,画出行和列
% % 定义一个24位图
% % imgmilkobj_rect=imcrop(imgmilkh,rect);
% % p = imgmilkobj_rect;
% p = imread(’.\裁剪\裁剪\51.jpg’);
%
% figure,imshow§;
% [m,n,p] = size§;
% hold on
% M = 3; % 水平分量
% N = 6; % 垂直分量
% linew = 1; % 划线宽度
% mx = ones(1,M+1);
% my = linspace(1,m,M+1);
% % 画水平线
% for k = 1:M+1
% line([mx(k) nmx(k)],[my(k) my(k)],‘color’,‘r’,‘LineWidth’,linew);
% end
% nx = linspace(1,n,N+1);
% ny = ones(1,N+1);
% % 画垂直线
% for k = 1:N+1
% line([nx(k) nx(k)],[ny(k) mny(k)],‘color’,‘r’,‘LineWidth’,linew);
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%画网格并把每个网格截取存储下来、
clc;
clear all;
tic;
b = imread(’.\裁剪\裁剪\5.jpg’);
rownumber = 3;
colnumber = 6;
rowpixel = 243;
colpixel = 210;
for x = 1:3
for y = 1:6
%%%%%%%%%%%%参数设置%%%%%%%%%%%%
m= (x-1)*rowpixel+1;
n= (y-1)*colpixel+1;
height= 243;
width= 210;
colpar1=255;
colpar2=0;
colpar3=0;
[b,p]=darwline(b,m,n,height,width,colpar1,colpar2,colpar3);
% %下面是对图像进行二值化,
% Level = 0.6;
% Pic1 = im2bw(p,Level);%灰度图二值化
% II =Pic1;
imshow§;
path=’.\网格’;
ss= y+(6*(x-1));
imwrite(p,strcat(path,num2str(ss),’.jpg’));
end
end