How to apply intensity difference of different level on the grayscale image?

1 visualización (últimos 30 días)
I created an image of a single alphabet at the middle(in white) with its background in black.I changed its font size to 5 different sizes,which are 58 to 66, increment by 2 each time.Next, I need to apply specific intensity difference level on the grayscale image,which is 20%,40%,60%,80%,100%.I am stucked at here, because it needs to apply the pixel value to the alphabet and its background with the corresponding intensity difference level.The formula used is shown as follow:
The code and images are attached as below:
%create blank image
w = 150;
h = 150;
blankImage= 255*ones(w,h,3,'uint8');
%position of the letter in the empty cell
position_x = (w+1)/2;
position_y = (h+1)/2;
% varying the font size, start from 10 to 16
font_start = 58;
font_end = 66;
num_fontsA = font_start:2:font_end;
% get the number of fonts
numImagesA = length(num_fontsA);
% create a cell array with number of fonts to fill in the image in next step
A = cell(1, numImagesA);
noise_start = 0.01;
noise_end = 0.05;
num_noiseimg = noise_start:0.01:noise_end
Total_noiseimg = length(num_noiseimg);
noiseimg_collection = cell(1,Total_noiseimg);
% for loop to create letter 'A'
% grayscale
% store into the cell array
for i=1:numImagesA
for font_size = num_fontsA(i)
image= insertText(blankImage,[position_x position_y],'A','Font','Times New Roman','FontSize',font_size,'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
grayImage= rgb2gray(image);
BWImage = imcomplement(grayImage);
background = BWImage == 0;
foreground = ~background;
Newforegnd = foreground;
% figure('Name','Background and Object');
subplot(5,1,i);
imshow(BWImage);
axis on;
title(sprintf('Font size of %d',font_size));
% Apply noise on the image
% Apply noise on the alphabet, using 0.01 standard deviation
pos = 1
for i=0.01:0.01:0.05
noiseimg_collection{pos} = imnoise(BWImage, 'gaussian',0, i);
pos=pos+1
end
end
end
Hope that anyone can guide me. Thank you!

Respuesta aceptada

Image Analyst
Image Analyst el 17 de Jul. de 2021
Isn't it just
intensityDifferencePercent = (100/255) * (max(grayImage(:) - min(grayImage(:)))
or am I missing something?
  7 comentarios
Image Analyst
Image Analyst el 18 de Jul. de 2021
You can use rescale(). Just figure out what the upper limit intensity should be and call rescale. For example
highIntensity = 0.2 * 255; % 20%
outputImage = uint8(rescale(inputImage, 0, highIntensity));
Tuck Wai Yip
Tuck Wai Yip el 18 de Jul. de 2021
Wow,I didn't think of this method, it is amazing.Thank you for your guidance.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by