ロゼッタコードでMATLABのハフ変換の実装を見つけましたが、理解するのに苦労しています。また、元の画像と再構成された線(デハフ)を表示するように変更したいと思います。
それを理解し、脱ハフするのに助けていただければ幸いです。ありがとう
画像が反転するのはなぜですか?
theImage = flipud(theImage);ノルム関数に頭を包むことができません。その目的は何ですか、そしてそれは避けることができますか?
編集:ノルムはユークリッド距離の同義語です:sqrt(width ^ 2 + height ^ 2)
rhoLimit = norm([width height]);
rho、theta、およびhoughSpaceが計算される方法/理由の説明を誰かが提供できますか?
rho = (-rhoLimit:1:rhoLimit); theta = (0:thetaSampleFrequency:pi); numThetas = numel(theta); houghSpace = zeros(numel(rho),numThetas);線を再作成するためにハフ空間をどのようにデハフしますか?
アイデンティティ(目)関数を使用して作成された対角線の10x10画像を使用して関数を呼び出す
theImage = eye(10)
thetaSampleFrequency = 0.1
[rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)
実際の機能
function [rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)
%Define the hough space
theImage = flipud(theImage);
[width,height] = size(theImage);
rhoLimit = norm([width height]);
rho = (-rhoLimit:1:rhoLimit);
theta = (0:thetaSampleFrequency:pi);
numThetas = numel(theta);
houghSpace = zeros(numel(rho),numThetas);
%Find the "edge" pixels
[xIndicies,yIndicies] = find(theImage);
%Preallocate space for the accumulator array
numEdgePixels = numel(xIndicies);
accumulator = zeros(numEdgePixels,numThetas);
%Preallocate cosine and sine calculations to increase speed. In
%addition to precallculating sine and cosine we are also multiplying
%them by the proper pixel weights such that the rows will be indexed by
%the pixel number and the columns will be indexed by the thetas.
%Example: cosine(3,:) is 2*cosine(0 to pi)
% cosine(:,1) is (0 to width of image)*cosine(0)
cosine = (0:width-1)'*cos(theta); %Matrix Outerproduct
sine = (0:height-1)'*sin(theta); %Matrix Outerproduct
accumulator((1:numEdgePixels),:) = cosine(xIndicies,:) + sine(yIndicies,:);
%Scan over the thetas and bin the rhos
for i = (1:numThetas)
houghSpace(:,i) = hist(accumulator(:,i),rho);
end
pcolor(theta,rho,houghSpace);
shading flat;
title('Hough Transform');
xlabel('Theta (radians)');
ylabel('Rho (pixels)');
colormap('gray');
end
