我有黑白图像。当我在图像查看器中查看此图像的特定coordinate (x,y)
时,我可以看到它的值为0
。但是,当我想从我的脚本中获得(x,y)
的价值时,我获得了255
。代码看起来如下:在matlab中确定黑色像素为白色
bw = imread('my_map.png');
imshow(bw);
hold on
% find corners of obstacles
corners = detectHarrisFeatures(bw);
plot(corners.selectStrongest(50));
cornerPoints = corners.selectStrongest(50);
hold on
% determine line's equation for two particular corners
m = cornerPoints.Location(4,2)-cornerPoints.Location(3,2);
n = cornerPoints.Location(4,1)-cornerPoints.Location(3,1);
k = (m)/(n);
b = cornerPoints.Location(3,2) - k*cornerPoints.Location(3,1);
%determine if this line intersects any obstacle
black = 0;
white = 0;
for y=cornerPoints.Location(3,2):1:cornerPoints.Location(4,2)
x = (y-b)/k;
if (int16(x) == 0)
x = cornerPoints.Location(3,1);
end
plot(int16(x),int16(y),'r*')
hold on
c = bw(int16(x), int16(y));
if (c==255)
white=white+1;
else
black=black+1;
end
end
if (white == 0)
display('valid')
else if (black <= 2)
display('valid')
else
display('invalid')
end
形象是这个
。
可能是什么问题?
我建议你添加一些代码。否则,我不认为你会得到答案。 – Lukasz
您可能需要注意坐标系统的原点。还要记住,MATLAB使用基于1的索引 – Amro