Hello guys.

I am currently developing an OCR tool using Chain-code algorithm in Java. I was googling and found this code in Matlab. I have no idea on using Matlab.

So, I need help from someone who's good in Matlab to convert it into Java. This will be a big help for me as I really need to get this code ready asap.

Here is the code:
1. checkones.m

function [c]=checkones(m,row,col)


c=0;
 if(row==1)
     c=1
 else
        if(m(row-1,col)==1)

             c=1 ;

        end
 end


return ;
  1. freeman.m

    function []=freeman()
    clc
    m=imread('C:\Documents and Settings\Desktop\msi.bmp');

    [h w d]=size(m);
    h;
    w;
    d;
    m
    row=0;
    col=0;
    for i=w:-1:1 % column
    for j=1:1:h % row
    % m(j,i)
    if(m(j,i)==0)
    row=j;
    col=i;
    break;
    end
    end
    end

    m(row,col);
    oldrow=row;
    oldcol=col;
    newrow=-1;
    newcol=-1;
    %while (row ~=newrow & col ~= newcol )
    for i=1:300;

     if(checkones(m,oldrow,oldcol)==1)%up 1
         %your up is 1 
         if(m(oldrow,oldcol+1)==1)%righ 1
             if(m(oldrow+1,oldcol)==1)%down 1
                break; 
             else
                      newrow=oldrow+1;
                        newcol=oldcol;
             end
         else
          newrow=oldrow;
     newcol=oldcol+1;   
    
         end
    
    
     else% your up is 0
         if(m(oldrow,oldcol+1)==1)%down 
                 newrow=oldrow+1;
                 newcol=oldcol;
         else if(m(oldrow,oldcol+1)==0 &m(oldrow,oldcol-1)~=1)% rigth
                     newrow=oldrow;
                newcol=oldcol+1;   
           else if(m(oldrow,oldcol-1)==1)% up    
         newrow=oldrow-1;
     newcol=oldcol;
         end
        end
    

    oldrow=newrow;
    oldcol=newcol;
    newrow
    newcol

    end

Hope any of you guys can help me on this. Thanks in advance.

Although it has been sometime since i last programmed in matlab , if i recollect properly , matlab code , in essence is a lot like C.. ie , procedural. java is OO . also , functions built into matlab , in many cases can be quite complicated , and implement complex algorithms, which can be difficult to translate effectively to java.

If you have done some programming in java , it would be better if you give it some effort yourself, write some startup code based on the algorithm you have in mind , and then post the code you have come up with. the members here would be happy to help you , but you have to show some effort of doing it yourself as well. thats only fair :)

I=imread('C:\Users\Ram\Desktop\download.jpg');Iycbcr=rgb2ycbcr(I);

I2=Iycbcr;

IY=Iycbcr( :,:,1);ICB=Iycbcr( :,:,2);ICR=Iycbcr( :,:,3);

skinplace = (80<IY) & (IY<190) & (57<ICB) & (ICB<148) & (120<ICR) & (ICR<180);

I1(repmat(skinplace,[1,1,3])) = 255;

imshow(Iycbcr)

figure,imshow(I2);

Idiff=Iycbcr-I2;

figure,imshow(Idiff);

Irgb=ycbcr2rgb(Iycbcr);

Igray=rgb2gray(Irgb);

Igray(find(Igray<=50))=0;

se=strel('disk',1);

Igray=imopen(Igray,se);

Igray=imfill(Igray,'holes');

se=strel('disk',6);

Igray=imopen(Igray,se);

figure,imshow(Igray);

Ibw=im2bw(Igray);

figure,imshow(Ibw);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.