Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Thinning algorithm in Octave, index error

I’m trying to code the Zhang Suen thinning algorithm using Octave. I’m not used at using Octave and I corrected many errors already, but there is this error: imgSeuil(0,_): subscripts must be either integers 1 to (2^63)-1 or logicals which explains that i’m trying to access a pixel of the image using incorrect index, but I didn’t find how to correct it. The mistake is probably obvious, I just need a fresh look at it. Here is some code:

        clear all;
        close all;
        
        img=imread("ED_3_6_originale.png");
        imshow(img);
        colorbar();
        
        sizeImg = size(img);
        NL=sizeImg(1,1);
        NC=sizeImg(1,2);
        
        tab=zeros(2,256); %grey lvl table
        tab(1,1:256)=0:255;
        
        %Grey level table and
        %chart printing
        for y=1:NL
            for x= 1:NC
                val=img(y,x);
                tab(2,val+1)=tab(2,val+1)+1;
            end
        end
        
        ticktab=zeros(1,25);
        
        for i=1:25
            ticktab(1, i)=10*i;
        end
        
        figure(2);
        plot(tab(1, 1:256),tab(2, 1:256));
        set(gca,'XTick',ticktab(1, 1:25));
        xlim([0, 255]);
        %seuillage de l'img
        figure(3);
        imgSeuil=img;
        for y=1:NL
            for x= 1:NC
                val=imgSeuil(y,x);
                if(val<30)
                    imgSeuil(y,x)=0;
                else
                    imgSeuil(y,x)=255;
                end
            end
        end
        imgSeuil=~imgSeuil;%inversion pour lignes blanches
        imshow(imgSeuil);
        
    
        %%%--------------
        
        %%stopCond=1;
        %%while stopCond = 1
          ap1 = 0;
          bp1 = 0;
          tabPixel = zeros(2,1);
          for x=2:NL-1
              for y= 2:NC-1
                p1 = imgSeuil(x,y);
                p2 = imgSeuil(x-1, y);
                p3 = imgSeuil(x-1, y+1);
                p4 = imgSeuil(x, y+1);
                p5 = imgSeuil(x+1, y+1);
                p6 = imgSeuil(x+1, y);
                p7 = imgSeuil(x+1, y-1);
                p8 = imgSeuil(x, y-1);
                p9 = imgSeuil(x-1, y-1);
                tabNeighbour = [p2, p3, p4, p5, p6, p7, p8, p9];
                tmpTabl = diff([tabNeighbour, p2]);
                tmpTabl = max(tmpTabl, 0);
                ap1 = sum(tmpTabl);
                bp1 = sum(tabNeighbour);
                
        ##        disp(bp1);
                if((p1==0)&&(bp1>=2)&&(bp1<=6)&&(ap1==1)&&
                  ((p2==1)||(p4==1)||(p6==1))&&
                  ((p4==1)||(p6==1)||(p8==1)))
                    tabPixel = [tabPixel, [x; y]];
                  endif
              endfor
          endfor
        ##  disp(tabPixel);
          for i=1:columns(tabPixel)
%%---------Error occurs on the next line ------%%
            imgSeuil(tabPixel(1, i), tabPixel(2, i)) = 255;
          endfor
       %%endwhile

The first step begins after %%%-----, I didn’t include the second because it’s almost the same.
The first lines are basically just printing the original picture, use a threshold to make it binary instead of grey scale.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

For i = 1 in your last loop, you’re indexing imgSeuil(tabPixel(1, 1), tabPixel(2, 1)), which evaluates to imgSeuil(0, 0), which is indeed impossible to index. You’ll need to change how you define it. Judging your code, either initialising as tabPixel = [], i.e. empty, or letting your final for loop run from i = 2 (or even removing the first column of tabPixel after your nested for loop), will all do the trick.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading