How can i select seed pixel based on intensity based similarity index (8 neighbour connectivity) ?

I am using this code . The similarity index between two pixels of RGB image is calculated by euclidean distance. I want to show these seed pixels in original image... clear all img=imread('ldy.jpg'); figure, imshow(img); imggray=rgb2gray(img); bw=edge(imggray, 'log'); % figure,imshow(bw); imgc=imcomplement(bw); % figure, imshow(imgc); w=watershed(imgc); % figure, imshow(w); wrgb=label2rgb(w); b=zeros(256, 256); figure, imshow(wrgb); for i=1:256; for j=1:256; dr1=wrgb(i, j, 1)-wrgb(i, j+1, 1); dg1=wrgb(i, j, 2)-wrgb(i, j+1, 2);db1=wrgb(i, j, 3)-wrgb(i, j+1, 3); d1=sqrt(dr1*dr1+dg1*dg1+db1*db1); dr2=wrgb(i, j, 1)-wrgb(i-1, j+1, 1); dg2=wrgb(i, j, 2)-wrgb(i-1, j+1, 2);db2=wrgb(i, j, 3)-wrgb(i-1, j+1, 3); d2=sqrt(dr2*dr2+dg2*dg2+db2*db2); dr3=wrgb(i, j, 1)-wrgb(i-1, j, 1); dg3=wrgb(i, j, 2)-wrgb(i-1, j, 2);db3=wrgb(i, j, 3)-wrgb(i-1, j, 3); d3=sqrt(dr3*dr3+dg3*dg3+db3*db3); dr4=wrgb(i, j, 1)-wrgb(i-1, j-1, 1); dg4=wrgb(i, j, 2)-wrgb(i-1, j-1, 2);db4=wrgb(i, j, 3)-wrgb(i-1, j-1, 3); d4=sqrt(dr4*dr4+dg4*dg4+db4*db4); dr5=wrgb(i, j, 1)-wrgb(i, j-1, 1); dg5=wrgb(i, j, 2)-wrgb(i, j-1, 2);db5=wrgb(i, j, 3)-wrgb(i, j-1, 3); d5=sqrt(dr5*dr5+dg5*dg5+db5*db5); dr6=wrgb(i, j, 1)-wrgb(i+1, j-1, 1); dg6=wrgb(i, j, 2)-wrgb(i+1, j-1, 2);db1=wrgb(i, j, 3)-wrgb(i+1, j-1, 3); d6=sqrt(dr6*dr6+dg6*dg6+db6*db6); dr7=wrgb(i, j, 1)-wrgb(i+1, j, 1); dg7=wrgb(i, j, 2)-wrgb(i+1, j, 2);db7=wrgb(i, j, 3)-wrgb(i+1, j, 3); d7=sqrt(dr7+dg7+db7); dr8=wrgb(i, j, 1)-wrgb(i+1, j+1, 1); dg8=wrgb(i, j, 2)-wrgb(i+1, j+1, 2);db8=wrgb(i, j, 3)-wrgb(i+1, j+1, 3); d8=sqrt(dr8+dg8+db8); d=d1+d2+d3+d4+d5+d6+d7+d8; if d==0 b(i, j)=1; end end end imshow(b); Error is genrated: Error in seedpixelselection (line 17) d1=sqrt(dr1*dr1+dg1*dg1+db1*db1);
Undefined function 'sqrt' for input arguments of type 'uint8'.

 Accepted Answer

It says it doesn't like uint8, so did you try casting it to double before taking the square root?

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!