matlab怎么把图像变清晰,如何使用MATLAB使黑板上的文字看起来更清晰?

本文介绍了使用MATLAB进行图像处理,特别是如何通过笔划宽度变换(SWT)来增强图像中文字的清晰度。通过代码示例展示了SWT的实现过程,包括基本转换、连接组件、中值滤波等步骤,帮助提升图像的识别效果。
摘要由CSDN通过智能技术生成

当要识别图像中的文本时,最好使用“ 笔划宽度变换”。

这是我在您的图像上获得的一些结果(基本转换+不带过滤的连接组件): SWT转换图像

我的mex实现基于此处的代码

#include "mex.h"

#include

#include

#include

#include

#include

using namespace std;

#define PI 3.14159265

struct Point2d {

int x;

int y;

float SWT;

};

struct Point2dFloat {

float x;

float y;

};

struct Ray {

Point2d p;

Point2d q;

std::vector points;

};

void strokeWidthTransform(const float * edgeImage,

const float * gradientX,

const float * gradientY,

bool dark_on_light,

float * SWTImage,

int h, int w,

std::vector & rays) {

// First pass

float prec = .05f;

for( int row = 0; row < h; row++ ){

const float* ptr = edgeImage + row*w;

for ( int col = 0; col < w; col++ ){

if (*ptr > 0) {

Ray r;

Point2d p;

p.x = col;

p.y = row;

r.p = p;

std::vector points;

points.push_back(p);

float curX = (float)col + 0.5f;

float curY = (float)row + 0.5f;

int curPixX = col;

int curPixY = row;

float G_x = gradientX[ col + row*w ];

float G_y = gradientY[ col + row*w ];

// normalize gradient

float mag = sqrt( (G_x * G_x) + (G_y * G_y) );

if (dark_on_light){

G_x = -G_x/mag;

G_y = -G_y/mag;

} else {

G_x = G_x/mag;

G_y = G_y/mag;

}

while (true) {

curX += G_x*prec;

curY += G_y*prec;

if ((int)(floor(curX)) != curPixX || (int)(floor(curY)) != curPixY)     {

curPixX = (int)(floor(curX));

curPixY = (int)(floor(curY));

// check if pixel is outside boundary of image

if (curPixX < 0 || (curPixX >= w) || curPixY < 0 || (curPixY >= h)) {

break;

}

Point2d pnew;

pnew.x = curPixX;

pnew.y = curPixY;

points.push_back(pnew);

if ( edgeImage[ curPixY*w+ curPixX ] > 0) {

r.q = pnew;

// dot product

float G_xt = gradientX[ curPixY*w + curPixX ];

float G_yt = gradientY[ curPixY*w + curPixX ];

mag = sqrt( (G_xt * G_xt) + (G_yt * G_yt) );

if (dark_on_light){

G_xt = -G_

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值