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

1 view (last 30 days)
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!

Accepted Answer

Image Analyst
Image Analyst on 17 Jul 2021
Isn't it just
intensityDifferencePercent = (100/255) * (max(grayImage(:) - min(grayImage(:)))
or am I missing something?
  7 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by