finding 4 neighbor of pixel in grayscale image.
i am trying to find the 4 neighbor of pixel x0,y0 in grayscale image but i getting empty x,y . her is the code i am using
function [x,y]= neighbours(image,x0,y0,thres)
image=double(image);
interest = image(x0,y0);
pixel =zeros(size(image));
pixel(x0,y0)=1;
x=[];
y=[];
up= image(conv2(pixel,[0 1 0; 0 0 0; 0 0 0],’same’)>0);
if abs(up- interest)<=thres
if isempty(up)~=1
x(1)=x0;
y(1)=y0-1;
end
end
down= image(conv2(pixel,[0 0 0; 0 0 0; 0 1 0],’same’)>0);
if abs(down- interest)<=thres
if isempty(down)~=1
x(2)=x0;
y(2)=y0+1;
end
end
left= image(conv2(pixel,[0 0 0; 1 0 0; 0 0 0],’same’)>0);
if abs(left- interest)<=thres
if isempty(left)~=1
x(3)=x0-1;
y(3)=y0;
end
end
right= image(conv2(pixel,[0 0 0; 0 0 1; 0 0 0],’same’)>0);
if abs(right- interest)<=thres
if isempty(right)~=1
x(4)=x0+1;
y(4)=y0;
end
end
endi am trying to find the 4 neighbor of pixel x0,y0 in grayscale image but i getting empty x,y . her is the code i am using
function [x,y]= neighbours(image,x0,y0,thres)
image=double(image);
interest = image(x0,y0);
pixel =zeros(size(image));
pixel(x0,y0)=1;
x=[];
y=[];
up= image(conv2(pixel,[0 1 0; 0 0 0; 0 0 0],’same’)>0);
if abs(up- interest)<=thres
if isempty(up)~=1
x(1)=x0;
y(1)=y0-1;
end
end
down= image(conv2(pixel,[0 0 0; 0 0 0; 0 1 0],’same’)>0);
if abs(down- interest)<=thres
if isempty(down)~=1
x(2)=x0;
y(2)=y0+1;
end
end
left= image(conv2(pixel,[0 0 0; 1 0 0; 0 0 0],’same’)>0);
if abs(left- interest)<=thres
if isempty(left)~=1
x(3)=x0-1;
y(3)=y0;
end
end
right= image(conv2(pixel,[0 0 0; 0 0 1; 0 0 0],’same’)>0);
if abs(right- interest)<=thres
if isempty(right)~=1
x(4)=x0+1;
y(4)=y0;
end
end
end i am trying to find the 4 neighbor of pixel x0,y0 in grayscale image but i getting empty x,y . her is the code i am using
function [x,y]= neighbours(image,x0,y0,thres)
image=double(image);
interest = image(x0,y0);
pixel =zeros(size(image));
pixel(x0,y0)=1;
x=[];
y=[];
up= image(conv2(pixel,[0 1 0; 0 0 0; 0 0 0],’same’)>0);
if abs(up- interest)<=thres
if isempty(up)~=1
x(1)=x0;
y(1)=y0-1;
end
end
down= image(conv2(pixel,[0 0 0; 0 0 0; 0 1 0],’same’)>0);
if abs(down- interest)<=thres
if isempty(down)~=1
x(2)=x0;
y(2)=y0+1;
end
end
left= image(conv2(pixel,[0 0 0; 1 0 0; 0 0 0],’same’)>0);
if abs(left- interest)<=thres
if isempty(left)~=1
x(3)=x0-1;
y(3)=y0;
end
end
right= image(conv2(pixel,[0 0 0; 0 0 1; 0 0 0],’same’)>0);
if abs(right- interest)<=thres
if isempty(right)~=1
x(4)=x0+1;
y(4)=y0;
end
end
end image segmentation, image processing, image analysis, matlab, digital image processing MATLAB Answers — New Questions