• 大小: 3KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-06
  • 语言: Matlab
  • 标签:

资源简介

以matlab为平台进行图像处理,预处理银行卡卡号后进行卡号定位,并自动切割出卡号部分的图像。代码注释明确,适合小白阅读。

资源截图

代码片段和文件信息

clear;
close all;
clc;

%% 弹出读取图像的提示框
[filename filepath] = uigetfile(‘.jpg‘ ‘输入一个需要识别的银行卡图像‘);
file = strcat(filepath filename);
img = imread(file);
figure;
imshow(img);
title(‘银行卡图像‘);

%% 灰度处理
img1 = rgb2gray(img);    % RGB图像转灰度图像
figure;
subplot(2 1 1);
imshow(img1);
title(‘灰度图像‘);
subplot(2 1 2);
imhist(img1);
title(‘灰度直方图‘);

%% 图像二值化
T=16 / 255;
bw22=im2bw(img1T);%转换图像为二进制图像
bw2=double(bw22);
figure;
imshow(bw2);
title(‘图像二值化‘);%得到二值图像

%% 边缘提取
img4 = edge(bw2‘canny‘); 
figure(‘name‘‘边缘检测‘);
imshow(img4);
title(‘canny算子边缘检测‘);

%% 图像腐蚀
se=[1;1;1];
img5 = imerode(img4 se);
figure(‘name‘‘图像腐蚀‘);
imshow(img5);
title(‘图像腐蚀后的图像‘);

%% 平滑图像,图像膨胀
se = strel(‘rectangle‘ [15 15]);
img6 = imclose(img5 se);
figure(‘name‘‘平滑处理‘);
imshow(img6);
title(‘平滑图像的轮廓‘);

%% 从图像中删除所有少于3000像素8邻接
img7 = bwareaopen(img6 500);
figure(‘name‘ ‘移除小对象‘);
imshow(img7);
title(‘从图像中移除小对象‘);

%% 切割出图像
[y x z] = size(img7);
img8 = double(img7);    % 转成双精度浮点型

评论

共有 条评论

相关资源