matlab - 如何在 MATLAB 中在我的原始图像上绘制线性回归线?
问题描述
我想在这张图片的边缘画一条红线,我想用线性回归来做,我已经得到了边缘的点,并通过图表上的点绘制了最好的线,但我不能t 找出如何使用这些信息在我的原始图像上绘制相同的线。
Image = imread('55-1_a.jpg');
imshow(Image)
binary_Image = imbinarize(Image);
[PIC_X, PIC_Y] = size(binary_Image);
imshow(binary_Image)
% i creat a matrix with two columns and PIC_X-1 rows
black_pixel_on_edge = zeros(PIC_Y , 2); % in each row i will save the lowest black point to use it later in the linear regression
for k = 1 : PIC_Y % i go through the columns of the image
black_pixel_on_edge(k, 1) = k;
for k2 = 1000 : 2000% i o through the rows
if( binary_Image(k2, k) == 0)%if the pixel is black i should save it in my array(WIDTH)
black_pixel_on_edge(k, 2) = k2;
end
end
end
%draw all the points from my Matrix
scatter(black_pixel_on_edge(:,1),black_pixel_on_edge(:,2));
axis equal tight;
h1 = lsline;% draw a line with linear regression
h1.Color = 'r';
%save the data of the red line
p2 = polyfit(get(h1,'xdata'),get(h1,'ydata'),1);
Slope_Of_Line = p2(1, 1);
Hight_Of_Line = p2(1, 2);
% here i just want to draw the same red line on my original 'Image'
解决方案
推荐阅读
- python - 字典列表到 Python 中的嵌套字典列表
- javascript - 在 tinymce 中添加自定义图片上传
- python - Python regex:删除所有未附加到单词的特殊字符和数字
- java - 从 sql server 检索数据对应于 Android Studio 中的 Edittext 值
- pytorch - 我们不能运行导入到 pytorch 的 onnx 模型吗?
- webpack - 如何使用 webpack 为特定块设置特定名称,同时为其他块使用哈希?
- android - 时间不显示在 android 9 及更高版本的通知上
- generator - 为什么生成器的 es5 转译代码有一段时间(1)
- django - 使用 Google OAuth2 和 Postman 进行身份验证
- autodesk-forge - Autodesk forge 是否仅支持 3D 模型演示?我可以显示二维平面图吗?