Clear Filters
Clear Filters

I want to ask about adaptive thresholding in my application

1 view (last 30 days)
I want to do the threshold in a slider and i don't know how, can anyone help me please

Accepted Answer

DGM
DGM on 17 Dec 2022
Edited: DGM on 17 Dec 2022
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);

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!