简体   繁体   中英

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.

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). You then perform std2 on it via blockproc . 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.

You then call im2bw without any inputs. 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). However, in your case, clearly most of the values are above 0.5, so the vast majority appears as white.

Two options:

1) Scale your image (for example, do im2double(I) when you pass it into blockproc
2) Give im2bw a threshold. You can calculate one automatically using graythresh , eg 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? Make sure it's scaled between 0 and 1, or im2double it before processing. This will save you from coming back here to ask a question about while the image you saved out appears to be blank.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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