0

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

bdecaf
  • 4,652
  • 23
  • 44

1 Answers1

3

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.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • how to save this pixel vaues – user2120268 May 28 '14 at 15:49
  • @user2120268 The positions of the black pixels will be in the matrix `[ii jj]`. If you're asking how to save the pixel coordinates to a file, you could use `dlmwrite('filename.txt', [ii jj])`. – beaker May 28 '14 at 17:37