📄 imageproperties.m
字号:
function Proc = ImageProperties(objectID,labeled)
% **********************************************************************************
% *
% * ImageProperties(objectID,labeled)
% *
% * objectID = object id
% * labeled = labeled image
% *
% * This function is used to detect the badminton racket among named objects.
% * This is little different to "ImagePropertiesInitial" because now we are not
% * processing the entire image but small part of it. Now we are tracking the image so
% * no need to scan the complete image. We can guess where the next badminton racket position going to be.
% * It uses shape descriptors to detect the badminton racket. It will return some
% * properties of the badminton racket too.
% *
% * Return Values
% *
% * arrOutPut(1) = objectID;
% * arrOutPut(2) = 0;
% * arrOutPut(3) = majorDist;
% * arrOutPut(4) = minorDist;
% * arrOutPut(5) = rotationAngle;
% *
% * arrOutPut(6) = topY;
% * arrOutPut(7) = bottomY;
% * arrOutPut(8) = leftX;
% * arrOutPut(9) = rightX;
% *
% *
% *
% * Author - I. Janaka Prasad Wijesena
% *
% **********************************************************************************
% this is the size of the image
imageSize = size(labeled);
% now we are going to calculate the avarage of the points. doing this we
% get the center of gravity of the bat. and it is on the bat !!!
gravX = 0;
gravY = 0;
topY = -1;
bottomY = -1;
leftX = -1;
rightX = -1;
area = 0;
for m = 1:imageSize(1)
for n = 1:imageSize(2)
if labeled(m,n) == objectID
area = area + 1;
if (topY > m) | (topY == -1)
topY = m;
end
if bottomY < m
bottomY = m;
end
if (leftX > n) | (leftX == -1)
leftX = n;
end
if rightX < n
rightX = n;
end
end
end
end
% round them up
gravX = round((leftX + rightX)/2);
gravY = round((topY + bottomY)/2);
% -------------------------------------------------------------------------------------------------------
% function Proc = ImageEdge(labeled,xLength,yLength,gX,gY,addX,addY)
% move up from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,0,1,gravX,gravY,1,0,objectID);
upPointX = edgePoint(1);
upPointY = edgePoint(2);
% move 1-5 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,5,gravX,gravY,1,0,objectID);
upRightPoint15X = edgePoint(1);
upRightPoint15Y = edgePoint(2);
% move 1-2 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,2,gravX,gravY,1,0,objectID);
upRightPoint12X = edgePoint(1);
upRightPoint12Y = edgePoint(2);
% move 3-3 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,1,gravX,gravY,1,0,objectID);
upRightPoint33X = edgePoint(1);
upRightPoint33Y = edgePoint(2);
% move 2-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,2,1,gravX,gravY,1,0,objectID);
upRightPoint21X = edgePoint(1);
upRightPoint21Y = edgePoint(2);
% move 5-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,5,1,gravX,gravY,1,0,objectID);
upRightPoint51X = edgePoint(1);
upRightPoint51Y = edgePoint(2);
% -------------------------------------------------------------------------------------------------------
% move up from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,0,gravX,gravY,1,1,objectID);
rightPointX = edgePoint(1);
rightPointY = edgePoint(2);
% move 1-5 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,5,gravX,gravY,1,1,objectID);
downRightPoint15X = edgePoint(1);
downRightPoint15Y = edgePoint(2);
% move 1-2 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,2,gravX,gravY,1,1,objectID);
downRightPoint12X = edgePoint(1);
downRightPoint12Y = edgePoint(2);
% move 3-3 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,1,gravX,gravY,1,1,objectID);
downRightPoint33X = edgePoint(1);
downRightPoint33Y = edgePoint(2);
% move 2-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,2,1,gravX,gravY,1,1,objectID);
downRightPoint21X = edgePoint(1);
downRightPoint21Y = edgePoint(2);
% move 5-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,5,1,gravX,gravY,1,1,objectID);
downRightPoint51X = edgePoint(1);
downRightPoint51Y = edgePoint(2);
% -------------------------------------------------------------------------------------------------------
% move up from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,0,1,gravX,gravY,1,1,objectID);
downPointX = edgePoint(1);
downPointY = edgePoint(2);
% move 1-5 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,5,gravX,gravY,0,1,objectID);
downLeftPoint15X = edgePoint(1);
downLeftPoint15Y = edgePoint(2);
% move 1-2 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,2,gravX,gravY,0,1,objectID);
downLeftPoint12X = edgePoint(1);
downLeftPoint12Y = edgePoint(2);
% move 3-3 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,1,gravX,gravY,0,1,objectID);
downLeftPoint33X = edgePoint(1);
downLeftPoint33Y = edgePoint(2);
% move 2-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,2,1,gravX,gravY,0,1,objectID);
downLeftPoint21X = edgePoint(1);
downLeftPoint21Y = edgePoint(2);
% move 5-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,5,1,gravX,gravY,0,1,objectID);
downLeftPoint51X = edgePoint(1);
downLeftPoint51Y = edgePoint(2);
% -------------------------------------------------------------------------------------------------------
% move up from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,0,gravX,gravY,0,1,objectID);
leftPointX = edgePoint(1);
leftPointY = edgePoint(2);
% move 1-5 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,5,gravX,gravY,0,0,objectID);
upLeftPoint15X = edgePoint(1);
upLeftPoint15Y = edgePoint(2);
% move 1-2 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,2,gravX,gravY,0,0,objectID);
upLeftPoint12X = edgePoint(1);
upLeftPoint12Y = edgePoint(2);
% move 3-3 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,1,1,gravX,gravY,0,0,objectID);
upLeftPoint33X = edgePoint(1);
upLeftPoint33Y = edgePoint(2);
% move 2-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,2,1,gravX,gravY,0,0,objectID);
upLeftPoint21X = edgePoint(1);
upLeftPoint21Y = edgePoint(2);
% move 5-1 from the gravity till you come to edge, record it
edgePoint = ImageEdge(labeled,5,1,gravX,gravY,0,0,objectID);
upLeftPoint51X = edgePoint(1);
upLeftPoint51Y = edgePoint(2);
% -------------------------------------------------------------------------------------------------------
totalDistance = sqrt((upPointX-upRightPoint15X)*(upPointX-upRightPoint15X) + (upPointY-upRightPoint15Y)*(upPointY-upRightPoint15Y)) + sqrt((upRightPoint12X-upRightPoint15X)*(upRightPoint12X-upRightPoint15X) + (upRightPoint12Y-upRightPoint15Y)*(upRightPoint12Y-upRightPoint15Y)) + sqrt((upRightPoint12X-upRightPoint33X)*(upRightPoint12X-upRightPoint33X) + (upRightPoint12Y-upRightPoint33Y)*(upRightPoint12Y-upRightPoint33Y)) + sqrt((upRightPoint21X-upRightPoint33X)*(upRightPoint21X-upRightPoint33X) + (upRightPoint21Y-upRightPoint33Y)*(upRightPoint21Y-upRightPoint33Y)) + sqrt((upRightPoint21X-upRightPoint51X)*(upRightPoint21X-upRightPoint51X) + (upRightPoint21Y-upRightPoint51Y)*(upRightPoint21Y-upRightPoint51Y)) + sqrt((rightPointX-upRightPoint51X)*(rightPointX-upRightPoint51X) + (rightPointY-upRightPoint51Y)*(rightPointY-upRightPoint51Y)) + ...
sqrt((rightPointX-downRightPoint51X)*(rightPointX-downRightPoint51X) + (rightPointY-downRightPoint51Y)*(rightPointY-downRightPoint51Y)) + sqrt((downRightPoint21X-downRightPoint51X)*(downRightPoint21X-downRightPoint51X) + (downRightPoint21Y-downRightPoint51Y)*(downRightPoint21Y-downRightPoint51Y)) + sqrt((downRightPoint21X-downRightPoint33X)*(downRightPoint21X-downRightPoint33X) + (downRightPoint21Y-downRightPoint33Y)*(downRightPoint21Y-downRightPoint33Y)) + sqrt((downRightPoint12X-downRightPoint33X)*(downRightPoint12X-downRightPoint33X) + (downRightPoint12Y-downRightPoint33Y)*(downRightPoint12Y-downRightPoint33Y)) + sqrt((downRightPoint12X-downRightPoint15X)*(downRightPoint12X-downRightPoint15X) + (downRightPoint12Y-downRightPoint15Y)*(downRightPoint12Y-downRightPoint15Y)) + sqrt((downPointX-downRightPoint15X)*(downPointX-downRightPoint15X) + (downPointY-downRightPoint15Y)*(downPointY-downRightPoint15Y)) + ...
sqrt((downPointX-downLeftPoint15X)*(downPointX-downLeftPoint15X) + (downPointY-downLeftPoint15Y)*(downPointY-downLeftPoint15Y)) + sqrt((downLeftPoint12X-downLeftPoint15X)*(downLeftPoint12X-downLeftPoint15X) + (downLeftPoint12Y-downLeftPoint15Y)*(downLeftPoint12Y-downLeftPoint15Y)) + sqrt((downLeftPoint12X-downLeftPoint33X)*(downLeftPoint12X-downLeftPoint33X) + (downLeftPoint12Y-downLeftPoint33Y)*(downLeftPoint12Y-downLeftPoint33Y)) + sqrt((downLeftPoint21X-downLeftPoint33X)*(downLeftPoint21X-downLeftPoint33X) + (downLeftPoint21Y-downLeftPoint33Y)*(downLeftPoint21Y-downLeftPoint33Y)) + sqrt((downLeftPoint21X-downLeftPoint51X)*(downLeftPoint21X-downLeftPoint51X) + (downLeftPoint21Y-downLeftPoint51Y)*(downLeftPoint21Y-downLeftPoint51Y)) + sqrt((leftPointX-downLeftPoint51X)*(leftPointX-downLeftPoint51X) + (leftPointY-downLeftPoint51Y)*(leftPointY-downLeftPoint51Y)) + ...
sqrt((leftPointX-upLeftPoint51X)*(leftPointX-upLeftPoint51X) + (leftPointY-upLeftPoint51Y)*(leftPointY-upLeftPoint51Y)) + sqrt((upLeftPoint21X-upLeftPoint51X)*(upLeftPoint21X-upLeftPoint51X) + (upLeftPoint21Y-upLeftPoint51Y)*(upLeftPoint21Y-upLeftPoint51Y)) + sqrt((upLeftPoint21X-upLeftPoint33X)*(upLeftPoint21X-upLeftPoint33X) + (upLeftPoint21Y-upLeftPoint33Y)*(upLeftPoint21Y-upLeftPoint33Y)) + sqrt((upLeftPoint12X-upLeftPoint33X)*(upLeftPoint12X-upLeftPoint33X) + (upLeftPoint12Y-upLeftPoint33Y)*(upLeftPoint12Y-upLeftPoint33Y)) + sqrt((upLeftPoint12X-upLeftPoint15X)*(upLeftPoint12X-upLeftPoint15X) + (upLeftPoint12Y-upLeftPoint15Y)*(upLeftPoint12Y-upLeftPoint15Y)) + sqrt((upPointX-upLeftPoint15X)*(upPointX-upLeftPoint15X) + (upPointY-upLeftPoint15Y)*(upPointY-upLeftPoint15Y));
%totalDistance
% -------------------------------------------------------------------------------------------------------
compactness = (totalDistance * totalDistance)/(4*pi*area);
%compactness
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -