[Image straight line fitting] Image straight line fitting based on matlab least squares method [including Matlab source code 100 period]

One, the source code

function chengxu()
%1
close all
I=imread('1.jpg');  %读取图像
I=rgb2gray(I);    %彩色图像转换成灰度图
 
% I=im2bw(I);      %二值化
I=edge(double(I)); %检测图像的边缘
figure
imshow(I)          %显示边缘检测的结果
 
%2
 
[m,n]=size(I);     %计算图像的尺寸
 
M=3;             %定义X方向分割的块数
N=3;             %定义Y方向分割的块数
mm=floor(m/M);   %子块行的长度
nn=floor(n/N);   %子块列的长度
count=1;         %计数器
figure
for i=1:M
    for j=1:N
        A=I((i-1)*mm+1:i*mm,(j-1)*nn+1:j*nn);    %分割原图像,得到一个子块
        subplot(M,N,count)
        imshow(A)               %显示一个子块
        zuoshangjiao=[(i-1)*mm+1 (j-1)*nn+1];  %子块左上角的坐标
        [x,y,k,b]=zikuai(A,zuoshangjiao);      %得到子块里白色像素点拟合得到的直线的斜率k和截距b(调用zikuai函数)
        X{
    
    count}=x;       %保存子块里所有白色像素的x坐标
        Y{
    
    count}=y;       %保存子块里所有白色像素的y坐标
        K(count)=k;       %保存子块里拟合得到的直线的斜率k
        B(count)=b;       %保存子块里拟合得到的直线的截距b
        count=count+1;    %计数器加1,进行下一个子块的计算
    end
end

Two, running results

Insert picture description here
Insert picture description here
Insert picture description here

3. Remarks

Complete code or writing add QQ2449341593 past review
>>>>>>
[Matlab 024] [Image processing 1] Image compression of Matlab image processing tutorial series
[Matlab 025] [Image processing 2] Matlab image processing tutorial series Image segmentation (1)
[Matlab 026 issue] [Image processing 3] Image segmentation of Matlab image processing tutorial series (2)
[Matlab 029] [Image processing 4] Matlab fingerprint recognition
[Matlab 030] [Image processing 5] Bank Card number recognition matlab source code
[Matlab 074] [Image processing 6] [Image clustering] Based on FCM and improved FCM brain CT image clustering processing
[Matlab 075] [Image processing 7] [Image evaluation] Based on CCF algorithm Image quality evaluation
[Matlab 076] [Image processing 8] [Image enhancement] CLAHE algorithm based on local contrast enhancement-histogram enhancement
[Matlab 077] [Image processing 9] [Image fusion] Image fusion based on Frequency Partition
[ Matlab Issue 078] [Image Processing 10] [Image Evaluation] Image quality evaluation based on svm without reference
[Image Edge Detection] Matlab source code of ellipse edge detection based on least square method [Matlab Issue 079] [Image Processing 11]
[Image Encryption] Image encryption and decryption based on chaotic system matlab source code with GUI [Matlab 080 period] [Image processing 12]
[Image processing] Based on DWT+DCT+PBFO to improve image watermark hiding and extraction matlab source code with GUI [Matlab 081 period] [Image processing 13]
[Image registration] Image registration matlab source code based on sift algorithm [Matlab 082] [Image processing 14]
[Image fusion] Image fusion matlab source code based on CBF algorithm [Matlab 083] [Image processing 15]
[Image segmentation] Image segmentation matlab source code based on random walk algorithm [Matlab 084] [Image processing 16]
[Image filtering] Image two-dimensional bilateral Gaussian filtering [Matlab 085] [Image processing 17]
[Image denoising] Based on adaptive morphology Image denoising [Matlab 086 issue] [Image processing 18]
[Image enhancement] DEHAZENET and HWD based underwater scattering image enhancement [Matlab 087] [Image processing 19]
[Image enhancement] PSO optimization ACE image enhancement matlab Source code [Matlab 088] [Image processing 20]
[Image enhancement] Gray-scale image enhancement based on region similarity transformation function and dragonfly algorithm [Matlab 089] [Image processing 21]
[Image reconstruction] ASTRA algorithm for image reconstruction [Matlab 090 [Image processing 22]
[Image segmentation] Image segmentation based on quadtree matlab source code [Matlab 091] [Image processing 23]
[Image segmentation] Heart centerline extraction [Matlab 092] [Image processing 24]
[Image recognition ] Based on svm plant leaf disease detection and classification [Matlab 093] [Image processing 25]
[Image recognition] Based on template matching handwritten number recognition system GUI interface [Matlab 094] [Image processing 26]
[Image recognition] based on unchanged Moment’s digital verification code recognition with GUI interface [Matlab 095] [Image processing 27]
[Image recognition] Barcode recognition system [Matlab 096] [Image processing 28]
[Image recognition] RMB recognition system based on RGB and BP neural network with GUI interface [Matlab 097] [Image processing 29]
[Image recognition] Matlab source code recognition based on cnn convolutional neural network [Matlab 098] [Image Processing 30]
[Image classification] Remote sensing image classification based on extreme learning classifier [Matlab Issue 099] [Image Processing 31]

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/113028306