나의 생물 학자 친구는 내가 도마뱀의 squam을 (이것은 적당한 번역인가?)에 프로그램을 만드는 것을 도울 수 있는지 나에게 물었다.도마뱀의 squama를 센다
그는 어떤 이미지를 보내고 Matlab에서 몇 가지 것을 시도했습니다. 일부 이미지의 경우 다른 이미지보다 훨씬 더 짙습니다 (예 : 어두운 영역이있는 경우). 적어도 내 방법으로. 나는 여기에 유용한 도움을 얻을 수있을 것이라고 확신한다. 어떻게 개선해야합니까? 나는 올바른 접근법을 취했는가?
다음은 일부 이미지입니다.
여기에 코드입니다 :
img0=imread('C:...\pic.png');
img1=rgb2gray(img0);
%The output image BW replaces all pixels in the input image with luminance greater than level with the value 1 (white) and replaces all other pixels with the value 0 (black). Specify level in the range [0,1].
img2=im2bw(img1,0.65);%(img1,graythresh(img1));
imshow(img2)
figure;
%erode
se = strel('line',6,0);
img2 = imerode(img2,se);
se = strel('line',6,90);
img2 = imerode(img2,se);
imshow(img2)
figure;
imshow(img1, 'InitialMag', 'fit')
% Make a truecolor all-green image. I use this later to overlay it on top of the original image to show which elements were counted (with green)
green = cat(3, zeros(size(img1)),ones(size(img1)), zeros(size(img1)));
hold on
h = imshow(green);
hold off
%counts the elements now defined by black spots on the image
[B,L,N,A] = bwboundaries(img2);
%imshow(img2); hold on;
set(h, 'AlphaData', img2)
text(10,10,strcat('\color{green}Objects Found:',num2str(length(B))))
figure;
%this produces a new image showing each counted element and its count id on top of it.
imshow(img2); hold on;
colors=['b' 'g' 'r' 'c' 'm' 'y'];
for k=1:length(B),
boundary = B{k};
cidx = mod(k,length(colors))+1;
plot(boundary(:,2), boundary(:,1), colors(cidx),'LineWidth',2);
%randomize text position for better visibility
rndRow = ceil(length(boundary)/(mod(rand*k,7)+1));
col = boundary(rndRow,2); row = boundary(rndRow,1);
h = text(col+1, row-1, num2str(L(row,col)));
set(h,'Color',colors(cidx),'FontSize',14,'FontWeight','bold');
end
figure;
spy(A);
그리고이 결과의 일부입니다. 왼쪽 상단 모서리에는 계산 된 개수가 표시됩니다.
또한 계산 된 요소를 초록색으로 표시하여 사용자가 수동으로 계산해야하는 요소를 알 수 있도록하는 것이 유용하다고 생각합니다. watershed segmentation :
나는이 문제에 더 많은 시간을 할애했으면 좋겠다. 정말로 흥미있는 소리가 난다! 나는 이미지를 선명하게하는 것으로 시작하고 선을 탐지하려고 시도 할 것입니다. (허벅지 변환을 사용하여) 보통 스쿼 머를 분리하는 직선이있는 것처럼 보입니다. 블랙 스퀘어가 있기 때문에 이미지를 뒤집을만한 가치가있을 수도 있습니다. –
라인 감지 사용을 고려하지 않았습니다!나는 시도와 업데이 트를 줄 것이다 :) Thanks @IvayloStrandjev – fersarr
당신은 로컬 콘트라스트 향상 필터와 Canny 에지 검출 알고리즘을 시도 할 수있다. – MBo