Please tell me the procedure to find the freeman chain code presentation of a character image?Kindly define value for each variable or number..What should I put in that variable?? Please help me out..

4 views (last 30 days)
a=imread('C:\Users\abcd\Desktop\scanned\mannu (daughter of poonam devi) 001.jpg');
bw=im2bw(a);
% FIND THE COORDIANTES OF THE FIRST OCCURENCE OF THE BALCK PIXEL OF THE
% GIVEN IMAGE
[r,c]=find(bw==0,1,'first');
%TRACE THE CONTOUR OF THE CHARACTER USING contour_trace.m
%contour_trace.m is downloaded from file Exchange
% Syntax :
% [pixel,I]=contour_trace(BW,r,c)
%
% Input :
% r,c - row, column value of a single pixel on the contour.
% BW - Black & White Image (Binary Image).
%
% Output :
% I - Binary Image containing just the desired contour.
% pixel - N x 2 matrix which stores the pixel value of the contour,
% column1 gives the rows & column2 the corresponding column.
[pixel,I]=contour_trace(bw,r,c);
%SWAPPED THE COLUMNS B'COZ THE b INPUT OF THE chaincode(b,unwrap) FUNCTION
%SHOULD BE (y,x) .
% INPUT:
% --------------------------------------------------------
% b - boundary as np-by-2 array;
% np is the number of pixels and each element is a pair (y,x) of
% pixel coordinates
% unwrap - (optional, default=false) unwrap code;
% if enable phase inversions are eliminated
%
b=cat(2,pixel(:,2),pixel(:,1));
% GENERATE THE CHAIN CODE
c=chaincode(b,true);
??? Undefined function or method 'contour_trace' for input arguments of type
'double'.
Error in ==> Untitled at 20
[pixel,I]=contour_trace(bw,r,c);

Answers (1)

Image Analyst
Image Analyst on 31 Jan 2015
Edited: Image Analyst on 31 Jan 2015
Why not simply use bwboundaries()???
  4 Comments
Image Analyst
Image Analyst on 31 Jan 2015
It gives you the x,y coordinates. Shouldn't that be good enough? Why do you want freeman code instead of the actual coordinates? If so, it's easy enough to do it with a for loop and a series of 8 if statements depending on which direction the next point is from the current point. I recommend you don't do that but if you feel you must, then go ahead. If you would like us to do it for you then I'd like an answer to my first two questions in this comment.
Ekta Sharma
Ekta Sharma on 29 Feb 2016
Edited: Walter Roberson on 29 Feb 2016
As per your suggestion i have tried to implement chain code but not getting desired results.Can you help?
clc;
clear;
close all;
I=imread('tool.png');
% imshow(I)
I2 = imcrop(I,[180 174 250 450]);
figure
imshow(I2)
im2double(I2);
t=graythresh(I2);
BW=im2bw(I2,t);
figure
imshow(BW)
J=bwperim(BW);
B=im2double(J);
imshow(B)
[M, N]=size(B);
p=7;
q=6;
h=5;
s=4;
t=3;
u=2;
v=1;
w=0;
for j=2:N-1
for i=2:M-1
if B(i,j)==1
fprintf('Element(%d,%d) = %d.\n',i,j,B(i,j))
x=i;
y=j;
while (x>=2 && y<=246)
if B(x+1,y+1)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,p)
x=x+1;
y=y+1;
break;
elseif B(x+1,y)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,q)
x=x+1;
y=y;
break;
elseif B(x+1,y-1)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,h)
x=x+1;
y=y-1;
break;
elseif B(x,y-1)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,s)
x=x;
y=y-1;
break;
elseif B(x-1,y-1)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,t)
x=x-1;
y=y-1;
break;
elseif B(x-1,y)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,u)
x=x-1;
y=y;
break;
elseif B(x-1,y+1)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,v)
x=x-1;
y=y+1;
break;
elseif B(x,y+1)==1
fprintf('The chain code for (%d,%d)= %d.\n',x,y,w)
x=x;
y=y+1;
break;
end
end
end
end
end

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!