user2120268
user2120268

Reputation: 3

Find black a pixel position in matlab

i want to find black pixel positions and save them. i used this code.

I= imread('bin_ecgm.png');

 imshow(I);

  [r c] =size(I);

   for j=1:c

    for i=1:r

        if(I(i,j)==1)
        [i j]    
        end
    end
end

how to store black pixel positions

Upvotes: 0

Views: 412

Answers (1)

Shai
Shai

Reputation: 114786

usually black pixels are I( ii, jj ) == 0... you can do that without a loop

[ii jj] = find( I == 0 ); % or I == 1 if you insist...

PS,
It is best not to use i and j as variable names in Matlab.

Upvotes: 3

Related Questions