How to create excel sheet for the following code

1 次查看(过去 30 天)
this is the code
i have converted an image into six faces(top, back, front,left, right, =bottom) for my preprocessing
1.now i need to write a loop for all faces and i need to save them seperately in the following format ( top_msss.jpg) for other faces too
2.i need to create an ecxel file for computation of entropy in each face
rows as (reference image, rating_2, rating_2, rating_3, rating_4, rating_5} and columns as (top_entropy, bottom_entropy, left_entropy, right entropy, back_entropy,front entropy_
after computation , entropy valued need to stored in excel sheet
pleasr help me as i am new to matlab
%---------------------------------------------------------
clear all; close all;
inputfilename = 'back_1.jpg';
img = imread(inputfilename);%Provide input image path
dim = size(img);
width = dim(2);height = dim(1);
gfrgb = imfilter(img, fspecial('gaussian', 3, 3), 'symmetric', 'conv');
%---------------------------------------------------------
% Perform sRGB to CIE Lab color space conversion (using D65)
%---------------------------------------------------------
cform = makecform('srgb2lab', 'AdaptedWhitePoint', whitepoint('d65'));
lab = applycform(gfrgb,cform);
l = double(lab(:,:,1));
a = double(lab(:,:,2));
b = double(lab(:,:,3));
%[l a b] = RGB2Lab(gfrgb(:,:,1),gfrgb(:,:,2), gfrgb(:,:,3));
%---------------------------------------------------------
% Create integral images
%---------------------------------------------------------
li = cumsum(cumsum(l,2));
ai = cumsum(cumsum(a,2));
bi = cumsum(cumsum(b,2));
%---------------------------------------------------------
% Compute Lab average values (note that in the paper this
% averages are found from the unblurred original image, but
% the results are quite similar)
%---------------------------------------------------------
sm = zeros(height, width);
sm2 = zeros(height, width);
for j = 1:height
yo = min(j, height-j);
y1 = max(1,j-yo); y2 = min(j+yo,height);
for k = 1:width
xo = min(k,width-k);
x1 = max(1,k-xo); x2 = min(k+xo,width);
invarea = 1.0/((y2-y1+1)*(x2-x1+1));
lm = iisum(li,x1,y1,x2,y2)*invarea;
am = iisum(ai,x1,y1,x2,y2)*invarea;
bm = iisum(bi,x1,y1,x2,y2)*invarea;
%---------------------------------------------------------
% Compute the saliency map
%---------------------------------------------------------
sm(j,k) = (l(j,k)-lm).^2 + (a(j,k)-am).^2 + (b(j,k)-bm).^2;
end
end
figure()
imshow(sm,[]);
back_entropy=entropy(sm)
%---------------------------------------------------------
  2 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2021-2-16
It is easy to answer if the question is asked for one specific issue at a time with sample data/examples/code.

请先登录,再进行评论。

回答(1 个)

Vatsal
Vatsal 2024-5-15
Hi,
Assuming you have a method to extract and process the six faces (top, back, front, left, right, bottom) from an image, the pseudocode below illustrates how you can loop through each face, process it, and save it using a defined naming convention.
faces = {'top', 'back', 'front', 'left', 'right', 'bottom'};
inputFileNames = {'top_1.jpg', 'back_1.jpg', 'front_1.jpg', 'left_1.jpg', 'right_1.jpg', 'bottom_1.jpg'}; % Example file names
outputFilePrefix = 'msss'; % Modify as needed
entropies = zeros(1, length(faces));
for i = 1:length(faces)
inputfilename = inputFileNames{i};
img = imread(inputfilename);
% iImage processing code here (similar to what you have provided for the back face)
face_entropy = entropy(sm);
% Construct output file name
outputFileName = sprintf('%s_%s.jpg', faces{i}, outputFilePrefix);
% Save the processed image
imwrite(img, outputFileName); % Modify this according to what you actually want to save
% Store the entropy values in an array or matrix for later use in Excel
entropies(i) = face_entropy;
end
To create an Excel file with specific rows and columns for the entropy values, you can utilize the "xlswrite" function. Assuming the entropy values for each face are stored in an array named "entropies", here is how you could write those values to an Excel file:
data = {'', 'Top_Entropy', 'Bottom_Entropy', 'Left_Entropy', 'Right_Entropy', 'Back_Entropy', 'Front_Entropy'; % Column headers
'Reference Image', entropies(1), entropies(2), entropies(3), entropies(4), entropies(5), entropies(6);
'Rating_2', '', '', '', '', '', ''; % Placeholder for actual ratings
'Rating_3', '', '', '', '', '', '';
'Rating_4', '', '', '', '', '', '';
'Rating_5', '', '', '', '', '', ''};
fileName = 'entropy_values.xlsx';
% Write data to Excel
xlswrite(fileName, data, 'Sheet1', 'A1');
I hope this helps!

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by