How to apply intensity difference of different level on the grayscale image?
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
Image Analyst
2021 年 7 月 17 日
Isn't it just
intensityDifferencePercent = (100/255) * (max(grayImage(:) - min(grayImage(:)))
or am I missing something?
7 件のコメント
Image Analyst
2021 年 7 月 18 日
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));
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Processing and Computer Vision についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!