1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| len = sqrt((lines(1).point1(1)-lines(1).point2(1))^2+(lines(1).point1(2)-lines(1).point2(2))^2); dm1 = imcomplement(dm1); dm1 = imrotate(dm1,lines(1).theta); dm1 = imcomplement(dm1); dm1 = im2bw(dm1,0.23); dm1 = imcrop(dm1,[size(dm1,1)/2-len/2 size(dm1,2)/2-len/2 len len]); figure; imshow(dm1);
a = round(len/12); cube = ones(a,a); result = zeros(12,12); for i = 1:a:size(dm1,1)-a for j = 1:a:size(dm1,2)-a tmp = dm1(i:i+a-1,j:j+a-1).*cube; if sum(tmp(:))/(a*a) > 0.4 result((i-1)/a+1,(j-1)/a+1) = 1; end end end result = result(2:11,2:11); figure;imagesc(result);axis equal,axis tight,axis off
|