허프만 변환 관련 질문
古いコメントを表示
결과가... 이상하게 나옵니다..
<주어진 함수 코드>
function res = hough2(image)
% input parameter is image
edges = edge(image,'canny');
[x,y] = find(edges);
angles=[-90:180]*pi/180;
r=int16(floor(x*cos(angles) + y*sin(angles)));
rmax = max(r(find(r>0)));
acc=zeros(rmax+1,270);
for i=1:length(x)
for j=1:270
if r(i,j) >=0
acc(r(i,j)+1,j) = acc(r(i,j)+1,j) + 1;
end
end
end
res = acc;
end
````````````````````````
function houghline(image,r,theta)
%UNTITLED3 이 함수의 요약 설명 위치
% 자세한 설명 위치
[x,y] = size(image);
angle = pi*(181-theta)/180;
X = [1:x];
if sin(angle) == 0
line([r r], [0,y],'Color','red');
else
line([0,y],[r/sin(angle),(r-y*cos(angle))/sin(angle)],'Color','red');
end
```````````````````````````````````````
<제가 작성한 코드>
%% Hough Transform
normalneck = imread('normalneck.PNG');
normalneck = im2gray(normalneck); % 안하면 차원 오류남.
textneck = imread('textneck.PNG'); % 거북목 증후군
textneck = im2gray(textneck);
% Apply Hough Transform
h1 = hough2(normalneck); figure, imshow(mat2gray(h1)*1.5);title('Hough1');
h2 = hough2(textneck); figure, imshow(mat2gray(h2)*1.5);title('Hough2');
sorted_h1 = sort(h1(:), 'descend');
sorted_h2 = sort(h2(:), 'descend');
figure, imshow(normalneck); hold on;
for i = 1:100
[r, theta] = find(h1 == sorted_h1(i));
houghline(normalneck, r, theta);
end
hold off;
figure, imshow(textneck); hold on;
for i = 1:100
[r, theta] = find(h2 == sorted_h2(i));
houghline(textneck, r, theta);
end
hold off;
``````````````````````````````````````
위의 코드를 실행하면,
-> 다음 사용 중 오류가 발생함: line
벡터들의 길이는 같아야 합니다.
오류 발생: houghline (11번 라인)
line([0,y],[r/sin(angle),(r-y*cos(angle))/sin(angle)],'Color','red');
이런 오류가 발생하면서 정답과는 다른 결과가 나옵니다...
어떻게 해결할 수 있을까요? ㅠㅠㅠ
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Image Category Classification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!