Hello,
I wanted to use bwskel to get a line down this image of a printed line. However, I am getting small line chunks of the outline instead. What am I doing wrong? The code I used is below and I attached the image.
img= imread('C:\Users\aluce\Documents\random lines\25g 1 10 PSI 5 MMS.jpg'); %put in image directly from FLIR camer
imgray = rgb2gray(img); % turn color image to greyscale
[imgray, rect] = imcrop(imgray); %opens up image, drag crop box, double click to select, rect coorinates use for crop
%%
BW = im2bw(imgray,0.8); % convert to binary image
%imshow(BW)
out = bwskel(BW);
imshow(out)

 채택된 답변

Image Analyst
Image Analyst 2020년 7월 27일

0 개 추천

Andrew:
After you binarized the image, there were some small holes in it that gave loops in the skeleton. I took the largest blob (to get rid of a noise speck) and then filled the holes in the remaining blob. Corrected code:
img= imread('25g 1 10 PSI 5 MMS.jpg'); %put in image directly from FLIR camer
imgray = rgb2gray(img); % turn color image to greyscale
subplot(2, 2, 1);
imshow(imgray, []);
% [imgray, rect] = imcrop(imgray); %opens up image, drag crop box, double click to select, rect coorinates use for crop
BW = im2bw(imgray, 0.8); % convert to binary image
% Take largest blob only.
BW = bwareafilt(BW, 1);
% Fill holes.
BW = imfill(BW, 'holes');
subplot(2, 2, 2);
imshow(BW, []);
%imshow(BW)
minBranchLength = round(sum(BW(:)) / 2)
skelImage = bwskel(BW, 'MinBranchLength', minBranchLength);
subplot(2, 2, 3);
imshow(skelImage)
g = gcf;
g.WindowState = 'maximized'

댓글 수: 5

Andrew Luce
Andrew Luce 2020년 7월 27일
Thank you, however, when I run this code, the skeleton is like 7 specks. I'm looking to have a line that traces down over the shape like in the bwskel examples.
Image Analyst
Image Analyst 2020년 7월 27일
Zoom in. You'll see it's continuous. It's just that when it subsamples that huge image to display it in a tiny viewport, some of the pixels are subsampled away. But you can see if you zoom in, or look at the matrix in the Workspace, that there actually is a continuous line. It's not just 7 specks.
Andrew Luce
Andrew Luce 2020년 7월 27일
oh man, I'm a dingus, thank you very much.
Andrew
Andrew Luce
Andrew Luce 2020년 8월 6일
So I use Hu moments to compare the binary image to an image of the original line ( which has nice sharp edges). Is there a way to flatten out the curve edges to give a better match?
Thnak you
Andrew
Image Analyst
Image Analyst 2020년 8월 6일
Well you could take a single color channel and threshold it. That would give sharp edges. But of course that was the first step in getting the skeleton image in the first place. So I guess I don't know what you think using Hu's moments would get you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

질문:

2020년 7월 27일

댓글:

2020년 8월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by