我正在尝试使用imageJ和Matlab检测图片中的断裂,这两者都是必需的。这是原始图片:
我已经建立了matlab和imageJ之间的连接,我已经在imageJ上打开了图像并开始做一些事情。首先,我使用imageJ菜单中的Find Edges函数来获取骨骼的轮廓。在我做了一个对比增强来增强轮廓。我现在的问题是,只有一个轮廓和一个黑色背景我怎么能做一个算法或类似的东西会告诉我线路没有连接? (意思是骨头有骨折)。当他发现sobel边缘检测时,我做了类似于该视频中的内容。
答案 0 :(得分:1)
仅在MATLAB中使用它。您可以使用霍夫变换来查找边缘滤波图像的最大贡献角度,然后使用该信息更进一步,并使用一些典型的图像处理技巧检测中断的位置。
对于任何不是您提供的图像的图像都没有任何承诺,但这些步骤可以合理地针对其他样本宽度进行优化。
img = imread('http://i.stack.imgur.com/mHo7s.jpg');
ImgBlurSigma = 2; % Amount to denoise input image
MinHoughPeakDistance = 5; % Distance between peaks in Hough transform angle detection
HoughConvolutionLength = 40; % Length of line to use to detect bone regions
HoughConvolutionDilate = 2; % Amount to dilate kernel for bone detection
BreakLineTolerance = 0.25; % Tolerance for bone end detection
breakPointDilate = 6; % Amount to dilate detected bone end points
%%%%%%%%%%%%%%%%%%%%%%%
img = (rgb2gray(img)); % Load image
img = imfilter(img, fspecial('gaussian', 10, ImgBlurSigma), 'symmetric'); % Denoise
% Do edge detection to find bone edges in image
% Filter out all but the two longest lines
% This feature may need to be changed if break is not in middle of bone
boneEdges = edge(img, 'canny');
boneEdges = bwmorph(boneEdges, 'close');
edgeRegs = regionprops(boneEdges, 'Area', 'PixelIdxList');
AreaList = sort(vertcat(edgeRegs.Area), 'descend');
edgeRegs(~ismember(vertcat(edgeRegs.Area), AreaList(1:2))) = [];
edgeImg = zeros(size(img, 1), size(img,2));
edgeImg(vertcat(edgeRegs.PixelIdxList)) = 1;
% Do hough transform on edge image to find angles at which bone pieces are
% found
% Use max value of Hough transform vs angle to find angles at which lines
% are oriented. If there is more than one major angle contribution there
% will be two peaks detected but only one peak if there is only one major
% angle contribution (ie peaks here = number of located bones = Number of
% breaks + 1)
[H,T,R] = hough(edgeImg,'RhoResolution',1,'Theta',-90:2:89.5);
maxHough = max(H, [], 1);
HoughThresh = (max(maxHough) - min(maxHough))/2 + min(maxHough);
[~, HoughPeaks] = findpeaks(maxHough,'MINPEAKHEIGHT',HoughThresh, 'MinPeakDistance', MinHoughPeakDistance);
% Plot Hough detection results
figure(1)
plot(T, maxHough);
hold on
plot([min(T) max(T)], [HoughThresh, HoughThresh], 'r');
plot(T(HoughPeaks), maxHough(HoughPeaks), 'rx', 'MarkerSize', 12, 'LineWidth', 2);
hold off
xlabel('Theta Value'); ylabel('Max Hough Transform');
legend({'Max Hough Transform', 'Hough Peak Threshold', 'Detected Peak'});
% Locate site of break
if numel(HoughPeaks) > 1;
BreakStack = zeros(size(img, 1), size(img, 2), numel(HoughPeaks));
% Convolute edge image with line of detected angle from hough transform
for m = 1:numel(HoughPeaks);
boneKernel = strel('line', HoughConvolutionLength, T(HoughPeaks(m)));
kern = double(bwmorph(boneKernel.getnhood(), 'dilate', HoughConvolutionDilate));
BreakStack(:,:,m) = imfilter(edgeImg, kern).*edgeImg;
end
% Take difference between convolution images. Where this crosses zero
% (within tolerance) should be where the break is. Have to filter out
% regions elsewhere where the bone simply ends.
brImg = abs(diff(BreakStack, 1, 3)) < BreakLineTolerance*max(BreakStack(:)) & edgeImg > 0;
[BpY, BpX] = find(abs(diff(BreakStack, 1, 3)) < BreakLineTolerance*max(BreakStack(:)) & edgeImg > 0);
brImg = bwmorph(brImg, 'dilate', breakPointDilate);
brReg = regionprops(brImg, 'Area', 'MajorAxisLength', 'MinorAxisLength', ...
'Orientation', 'Centroid');
brReg(vertcat(brReg.Area) ~= max(vertcat(brReg.Area))) = [];
% Calculate bounding ellipse
brReg.EllipseCoords = zeros(100, 2);
t = linspace(0, 2*pi, 100);
brReg.EllipseCoords(:,1) = brReg.Centroid(1) + brReg.MajorAxisLength/2*cos(t - brReg.Orientation);
brReg.EllipseCoords(:,2) = brReg.Centroid(2) + brReg.MinorAxisLength/2*sin(t - brReg.Orientation);
else
brReg = [];
end
% Draw ellipse around break location
figure(2)
imshow(img)
hold on
colormap('gray')
if ~isempty(brReg)
plot(brReg.EllipseCoords(:,1), brReg.EllipseCoords(:,2), 'r');
end
hold off