How to display all image in cell array using loop for each dimensions?
Afficher commentaires plus anciens
I have problem to display image using imshow,it does not show all image for each intensity difference from variable IntDiff_no for each index,can anyone guide and tell me where is wrong for the code?The code is inserted as below.
for i=1:numImages
for font_size = num_fonts(i)
figure('Name','Sauvola thresholding with %f font size,%f percent ','NumberTitle','off');
for IntDiff_no=1:each_intensityDifference
for IntDiff_percentage= intensityDifference(IntDiff_no)
for Noise_no =1:each_noise
for noise= num_noiseimg(Noise_no)
subplot(5,1,Noise_no)
imshow(alphabetSauvImage_collection{i,IntDiff_no,Noise_no});
title(sprintf('Image with %f font size %f intensity difference %f noise',font_size,IntDiff_percentage,noise));
end
end
end
end
end
end
The for loop above is the for loop that I faced the problem.I aim to display image subplot with varying noise, but for same font size and same intensity difference,so in total it will have 25 figures.Hope to guide from someone.Thank you.
%create blank image
w = 200;
h = 200;
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 80 to 160
font_start = 100;
font_end = 180;
num_fonts = font_start:20:font_end;
% get the number of fonts
numImages = length(num_fonts);
% create a cell array with number of fonts to fill in the image in next step
Output_collection = cell(1, numImages);
Orig_grayImage = cell(1, numImages);
alphabet_segmented = cell(5,5,5);
check_foreground = cell(5,5,5);
% alphabet_Uppercase = cell(1,26);
% alphabet_Uppercase = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
Int_image_array = cell(1, numImages);
A = cell(1, numImages);
Binaryimg = cell(1, numImages);
alphabet_orginal = cell(1, numImages);
% alphabet_Image = cell(26,5);
noise_start = 0.005;
noise_end = 0.025;
num_noiseimg = noise_start:0.005:noise_end;
each_noise = length(num_noiseimg);
alphabetNoiseimg_collection = cell(5,5,5);
alphabetSauvImage_collection = cell(5,5,5);
true = 0;
noise_pos = 1;
Int_image = cell(1, numImages);
intensityDifference = 20:20:100;
intensityDifference = round(intensityDifference);
each_intensityDifference=length(intensityDifference);
zeta = cell(5,5,5);
zeta_array = zeros(5,5,5);
zeta_array_intnoise = zeros(5,5);
zeta_array_fontnoise = zeros(5,5);
zeta_array_fontint = zeros(5,5);
check_value = zeros(1,125);
%%
% for loop to create letter 'A'
% grayscale
% store into the cell array
% for all_alphabet=1:
for i=1:numImages
for font_size = num_fonts(i)
Orgimage= insertText(blankImage,[position_x position_y],'A','Font','Times New Roman','FontSize',font_size,'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
grayImage= rgb2gray(Orgimage);
BWImage = imcomplement(grayImage);
A{1,i} = BWImage;
Orig_grayImage{1,i} = A{1,i};
Binaryimg{1,i} = imbinarize(Orig_grayImage{1,i});
alphabet_orginal{1,i} = sum(Binaryimg{1,i}(:));
% figure(i);
% imshow(A{1,i});
% impixelinfo;
% background = BWImage == 0;
% foreground = ~background;
% Newforegnd = foreground;
b=insertText(blankImage,[position_x position_y],'b','Font','Times New Roman', 'FontSize', font_size, 'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
o=insertText(blankImage,[position_x position_y],'o','Font','Times New Roman Bold', 'FontSize', font_size, 'TextColor','black','BoxColor','w','BoxOpacity',0,'AnchorPoint','Center');
BWImage_bin = imbinarize(BWImage);
out = repmat('b',size(BWImage_bin));
BoldO = '<strong>o</strong>';
out(BWImage_bin) = 'o';
display(out);
Output_collection{1,i} = out;
% subplot(5,1,i);
% imshow(BWImage);
% axis on;
%
for IntDiff_no=1:each_intensityDifference
for IntDiff_percentage= intensityDifference(IntDiff_no)
% backgroundGrayLevel = IntDiff_percentage;
% Int_image = A{1,i};
% background_range = A{1,i} ==0;
% Int_image(background_range)= backgroundGrayLevel;
% foregroundGrayLevel = backgroundGrayLevel + ((backgroundGrayLevel/100)*255);
% foreground_range = A{1,i} ==255;
% Int_image(foreground_range) = foregroundGrayLevel;
% Int_image_array{i,IntDiff_no} = Int_image;
highIntensity = (IntDiff_percentage/100)* 255; % 20%
Int_image = uint8(rescale(A{1,i}, 0, highIntensity));
Int_image_array{i,IntDiff_no} = Int_image;
figure('Name',sprintf('Font size of %d for Gaussian noise',font_size),'NumberTitle','off');
for Noise_no =1:each_noise
for noise= num_noiseimg(Noise_no)
% Apply Gaussiannoise on the alphabet,
%using 0.01 to 0.05 (increament of 0.01 per step)standard deviation
NoiseImg = imnoise(Int_image_array{i,IntDiff_no}, 'gaussian',0, noise);
alphabetNoiseimg_collection{i,IntDiff_no,Noise_no}=NoiseImg;
%apply sauvola's thresholding
%m is mean value
%k is a constant between 0.2 to 0.5%
%s is standard deviation
%R is gray level
%figure('Name',sprintf('Image of alphabet with font size %d ',font_size),'NumberTitle','off');
%S = m* (1 + k * (s/R - 1));
%R = 128;
%k = 0.2;
sauvImage = sauvola(NoiseImg, [200 200]);
alphabetSauvImage_collection{i,IntDiff_no,Noise_no} = sauvImage;
%for checking total image
% fprintf('i is%d',i);
% imshow(sauvImage);
% figure('Name','Sauvola thresholding bef and after','NumberTitle','off');
Image_segmented = nnz(sauvImage);
alphabet_segmented{i,IntDiff_no,Noise_no}= Image_segmented;
check_foreground{i,IntDiff_no,Noise_no} = sum(sauvImage(:));
zeta{i,IntDiff_no,Noise_no} = alphabet_segmented{i,IntDiff_no,Noise_no}/alphabet_orginal{1,i};
zeta_array(i,IntDiff_no,Noise_no) = alphabet_segmented{i,IntDiff_no,Noise_no}/alphabet_orginal{1,i};
zeta_array_intnoise(IntDiff_no,Noise_no) = alphabet_segmented{i,IntDiff_no,Noise_no}/alphabet_orginal{1,i};
zeta_array_fontnoise(i,Noise_no) = alphabet_segmented{i,IntDiff_no,Noise_no}/alphabet_orginal{1,i};
zeta_array_fontint(i,IntDiff_no) = alphabet_segmented{i,IntDiff_no,Noise_no}/alphabet_orginal{1,i};
% plot(num_noiseimg,zeta_array);
% = zeta_array;
if alphabet_segmented{i,IntDiff_no,Noise_no} == check_foreground{i,IntDiff_no,Noise_no}
true = true +1;
end
end
end
end
end
figure('Name',sprintf('Font size of %d for Intensity Difference',font_size),'NumberTitle','off');
for int_no =1:IntDiff_no
subplot(5,1,int_no);
imshow(Int_image_array{i,int_no});
axis on;
title(sprintf('Intensity difference %d percent for alphabet',intensityDifference(int_no)));
end
end
end
% fprintf('%d of sauvola image',true);
figure('Name','Image with different font_size','NumberTitle','off');
for font_no =1:numImages
for each_font = num_fonts(font_no)
subplot(5,1,font_no);
imshow(Orig_grayImage{1,font_no});
axis on;
title(sprintf('Image with %d font size',each_font));
end
end
for i=1:numImages
for font_size = num_fonts(i)
figure('Name','Sauvola thresholding with %f font size,%f percent ','NumberTitle','off');
for IntDiff_no=1:each_intensityDifference
for IntDiff_percentage= intensityDifference(IntDiff_no)
for Noise_no =1:each_noise
for noise= num_noiseimg(Noise_no)
subplot(5,1,Noise_no)
imshow(alphabetSauvImage_collection{i,IntDiff_no,Noise_no});
title(sprintf('Image with %f font size %f intensity difference %f noise',font_size,IntDiff_percentage,noise));
end
end
end
end
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!