I want to ask about adaptive thresholding in my application
1 次查看(过去 30 天)
显示 更早的评论
采纳的回答
DGM
2022-12-17
编辑:DGM
2022-12-17
I have no idea what the goal is here, but I'm going to guess that it's also not generally correctly scaled. Is there any reason to believe that the source image is always 256x256? If not, then it won't work.
x=ones(256,1)*[1:256]; % this is always 256x256
c2=double(input).*(x/2+50)+(1-double(input)).*x/2;
% (1-double(input)) implies that input is already class 'double'
% so it's either incorrect inversion or redundant casting
Unless you intend to normalize the image, you shouldn't result to normalization for the simple purpose of class conversion. Maintain the proper scaling and scale the images accordingly when converting instead of blindly discarding information by normalizing.
c3=unit8(256*mat2gray(c2));
Also, it's uint8(), not unit8()
Here's my guess
% get image
a = imread('peppers.png');
inpict = im2gray(a);
% convert once instead of multiple times
% keep image scaled correctly for its class
inpict = im2double(inpict);
% generate gradient that's correctly scaled for its class
sz = size(inpict);
xgrad = repmat(linspace(0,0.5,sz(2)),[sz(1) 1]);
% composite gradients using the image as a mask
offset = 50/255;
c2 = inpict.*(xgrad+offset) + (1-inpict).*xgrad;
% cast and rescale to uint8
% contrast is preserved because the image isn't blindly normalized
c3 = im2uint8(c2);
% display it
imshow(c3);
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!