I need to programe a thinning function without using toolbox. I can get thinning image with toolbox functions, the problem is that I can't use it.

I have use this comands for avoid the noise and to put the image in 2D
im = imread('Vstup.jpg');
im = rgb2grayscale(im);
im1 = medop(im);
im2 = uint8(im1);
im3 = im2>82 | im2<8;
With toolbox fuction I obtain this:
toolbox function solution:
f = imread('Vstup.jpg');
f = im2double(f);
f = rgb2grayscale(imread('Vstup.jpg'));
f = im2double(f);
h = fspecial('gaussian',4,6);
g = imfilter(f,h,'replicate');
g = im2bw(g,1.12*graythresh(g));
s = bwmorph(g,'skel',Inf);
figure,imshow(s);
(I need something similar to that, I only need the thinning function). The teacher say that I can use rot90 for eliminate the pixel and do the thinning function, but any help is good for me.
Thank you very much, Alejandro :)

5 Comments

I forget to put the medop and rgb2grayscale commands, I insert here
function [Y]=rgb2grayscale(F)
R = F(:,:,1);
G = F(:,:,2);
B = F(:,:,3);
Y = 0.2989*R + 0.5870*G + 0.1140*B;
end
:
function R = medop(I,B,s)
% R = medop(I,B,s) - Median filter (iterative) implemented as a set operator
% I - input image
% B - mask for median, typically B = ones(3) (default)
% s - number of levels, 1 for binary object (default)
if nargin < 2
B = ones(3);
end
if nargin < 3
s = 1;
end
I = double(I);
B = B/sum(B(:));
minV = min(I(:));
maxV = max(I(:));
R = zeros(size(I));
for l=minV:maxV
M = I>=l;
for i=1:s
M = conv2(double(M),B,'same')>=0.5;
end
R(M) = l;
end
Please clarify what question you are asking.
It sounds like you might not be permitted to use something, but it is not clear what you are not permitted to use
I can´t use Image Processing Toolbox Functions.
I have done this to have a 2D black and white image:
im = imread('Vstup.jpg');
im = rgb2grayscale(im);
im1 = medop(im);
im2 = uint8(im1);
im3 = im2>82 | im2<8;
With the functions I wrote before, and I have to do a thinning function.
Thank you very much, Alejandro
I don't see how that code does any thinning at all. Thinning is a morphological function that erodes an image without breaking the blobs.
Anyway, if you can't use toolbox functions then it's probably also not allowed for us to just hand over alternate code for doing it that you can hand in either. So good luck.

Sign in to comment.

Answers (1)

There is a MATLAB CENTRAL solution already available that apparently does the 'image thinning' you are after.
If you find this answer of any help solving this question, please click on the thumbs-up vote link,
thanks in advance
John

Asked:

on 4 Mar 2016

Commented:

on 5 Mar 2016

Community Treasure Hunt

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

Start Hunting!