我有黑白圖像。當我在圖像查看器中查看此圖像的特定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