简体   繁体   English

Matlab图像块处理

[英]Matlab image block processing

clear
I = imread('punk.jpg');
figure; imshow(I);
B=blockproc(I, [4 4], @(x) std2(x.data(:)));
figure;
imshow(B,[]);
J = imresize(B, 4);
figure;
imshow(J,[]);

BW = im2bw(J);
figure;
imshow(BW);

结果

What i want, is get an image, break it in nxn blocks, apply standard deviation to each one and then make it binary. 我想要的是获取一张图像,将其分成nxn个块,将标准偏差应用于每个图像,然后使其变为二进制。

All these as part of getting the text from an image. 所有这些都是从图像获取文本的一部分。 So far i want to figure out the regions of interest. 到目前为止,我想弄清楚感兴趣的区域。

Why is the 3rd image as it is though? 为什么第三个图像是原样的?

Original image: 原始图片:

在此处输入图片说明

Scaling. 缩放比例。

You load in an image which probably contains uint8 values (0 to 255). 您加载的图像可能包含uint8值(0到255)。 You then perform std2 on it via blockproc . 然后,您可以通过blockproc在其上执行std2 The output of this will be of type double , but it hasn't been scaled so the values in it will be of a similar order of magnitude to the original. 此输出的类型将为double ,但尚未缩放,因此其中的值将与原始值具有相似的数量级。

You then call im2bw without any inputs. 然后,您无需任何输入即可调用im2bw This sets the threshold level to 0.5, which is a reasonable setting if you presume that images of type double are scaled between 0 and 1 (standard assumption made by many MATLAB image processing). 这会将阈值级别设置为0.5,如果您假设double类型的图像在0到1之间缩放(许多MATLAB图像处理做出的标准假设),则这是一个合理的设置。 However, in your case, clearly most of the values are above 0.5, so the vast majority appears as white. 但是,在您的情况下,显然大多数值都大于0.5,因此绝大多数显示为白色。

Two options: 两种选择:

1) Scale your image (for example, do im2double(I) when you pass it into blockproc 1)缩放图像(例如,将图像传递到blockproc时执行im2double(I)
2) Give im2bw a threshold. 2)给im2bw一个阈值。 You can calculate one automatically using graythresh , eg BW = im2bw(J,graythresh(J)); 您可以使用graythresh自动计算一个,例如BW = im2bw(J,graythresh(J));

Note that this scaling issue will have impacts on other image processing processes and saving images out. 请注意,此缩放问题将影响其他图像处理过程并保存图像。 Image of type double, or you're going to do processing on it which makes it double? 类型为double的图像,或者您要对其进行处理以使其变为double? Make sure it's scaled between 0 and 1, or im2double it before processing. 确保在0到1之间缩放比例,或者在处理之前将其缩放2 im2double This will save you from coming back here to ask a question about while the image you saved out appears to be blank. 这样可以避免您回到此处询问有关保存的图像为空白的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM