How to apply intensity difference of different level on the grayscale image?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tuck Wai Yip
le 17 Juil 2021
Commenté : Tuck Wai Yip
le 18 Juil 2021
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/687123/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/687128/image.png)
Hope that anyone can guide me. Thank you!
0 commentaires
Réponse acceptée
Image Analyst
le 17 Juil 2021
Isn't it just
intensityDifferencePercent = (100/255) * (max(grayImage(:) - min(grayImage(:)))
or am I missing something?
7 commentaires
Image Analyst
le 18 Juil 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));
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Processing and Computer Vision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!