How can write names of image / file in excel sheet using matlab ?

I need to print name of an image or current browsed file in specific position in excel using matlab Here is the code of what I tried so far
Image2 = imread('D:\ahmed','jpeg');
xlswrite('D:\aa.xls',image2,'Sheet1','A1');
OR ..
when i need to print name of browse image in GUI .. how can i print name of this upload image in excel sheet ...
filename=handles.filename;
[X2] = imread(filename);
xlswrite('D:\aa.xls',[X2],'Sheet1','A1');
both codes don't write the name of image ... its give me name of variable (image2 or X2 ) and do not write name of image ahmed or name of image in X2 which i browsed ... any help please .
hope to get the following output :
excel sheet1 cell [A1] contain (( name of my image or browsed image name like wilyam or browsed image name ).

6 commentaires

Yeah, so.....?
Hello sir .. i edited my question to be more clearly ..
If you want to write the image's attribute in xls,you can write follow as:
Image1= 'D:\ahmed.jpeg'; % we make Image be an string variable
Image2={Image1}; % cell array is necessary
xlswrite('D:\aa.xls',image2,'Sheet1','A1');% if aa.xls don't exist ,some error will appear.
aa excel file exist , but still give me an error
??? Error using ==> xlswrite at 213 ActiveX - Elements of cell array must have 2 dimensions.
Did you even TRY my answer below? It works, even if the file already exists, and doesn't give any error.
yes i tried it , but its .. in this case when i browsed an image which its name differ each time
filename=handles.filename;
[X2] = imread(filename);
I3=rgb2gray(X2);
figure,imshow(I3)
xlswrite('D:\aa.xls',I3,'Sheet1','A1');
its does not write the name of this image .. how can write the name of this image please

Connectez-vous pour commenter.

 Réponse acceptée

I think this should cover whatever case you want to do. It writes out both the filename string into cell A1, and the full uint8 numerical array into a bunch of cells with the upper left corner at cell A2 of the worksheet:
% Have user browse for a file, from a specified "starting folder."
% For convenience in browsing, set a starting folder from which to browse.
startingFolder = 'D:\ahmed'; % Specify where starting folder is that the user starts browsing from..
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
% Read in the file into a variable called X2.
[X2] = imread(fullFileName);
imshow(X2, []);
drawnow;
% Construct the output workbook name.
excelFullFileName = fullfile(pwd, 'aa.xlsx');
% Now write out the filename string to cell A1 of a workbook called aa.xlsx.
% fullFileName needs to be put into a cell otherwise it will put one character
% of the filename into each cell along row 1 of the worksheet.
% To put into a cell, wrap the fullFileName variable in braces.
xlswrite(excelFullFileName, {fullFileName}, 'Sheet1', 'A1');
% Next write out the actual image array to cell A2 of a workbook called aa.xlsx.
% This takes a long time so be patient.
xlswrite(excelFullFileName, X2, 'Sheet1', 'A2');
% Launch Excel opened to this workbook.
winopen(excelFullFileName);

8 commentaires

great work sir ... only small error i got .. what its this
Error using xlswrite Dimension of input array cannot be higher than two.
You can't use it for 3 or higher dimensions. So if you want to write out a color image you'll have to do it one color channel at a time:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Write the color channels out to separate worksheets.
xlswrite(excelFullFileName, redChannel, 'Red Channel', 'A2');
xlswrite(excelFullFileName, greenChannel, 'Green Channel', 'A2');
xlswrite(excelFullFileName, blueChannel, 'Blue Channel', 'A2');
thanks for replay sir ... i need just write the name of this image its like store an image name in string variable and print that name in an excel sheet any cell , its required to convert or calculate color channels for it ... there is no any way to print the name of this image .. like in cell A1 = Ahmed ... that's all which mean Ahmed its an image name thanks a lot your code its so great ,, thanks again
ahmed, I'm not sure what you want. I showed you how to save the name of the image file in a string. If your image filename string is "D:\ahmed.jpg", and you want just ahmed, then use fileparts:
[folder, baseFilename, ext] = fileparts(fullFileName)
% Write 'ahmed' into cell C1 of worksheet "Red Channel".
xlswrite(excelFullFileName, {baseFilename}, 'Red Channel', 'C1');
I also showed you how to save a gray scale image, as well as separate color channels of a color image.
If you want the name of the variable , like "X2", in a cell of your workbook, then you'll have to write that in manually
% Write 'X2' into cell D1 of worksheet "Red Channel".
xlswrite(excelFullFileName, 'X2', 'Red Channel', 'D1');
thank you sir ... all codes very useful for me thanks for every thing ... its working very well .. but sir its open an aaa.xls file and show me image name whats i need to print ,,, but in case of i need to save this value i should give it save otherwise don't save that value . i need to print this value directly and don't wait me to give save or not . thanks again
I don't really understand what you're saying. Either try to have a native English speaker review this or else give screenshots of what you're getting and what you're like to get instead - because, sorry, but I don't really know how to answer you.
If you want to "print this value directly" then use fprintf(). That's about all I can guess at for an answer.
thank you a lot sir .. i solved my problem based on your help ... your codes help me more .. please accept my apologies for confuse with my best regards ..

Connectez-vous pour commenter.

Plus de réponses (3)

munah alhatmi
munah alhatmi le 27 Mar 2016
please, could you help me in something similar....
I am working with image enhancement based soft computing using matlab...
I got the result of some filters and i had stored the result in excel file to be used later as input in neural network....
however, I need to save the result from neural stage and display again as image.
i mean how to store the result of xls file to jpg file.
i am looking for your help..
thanks in advance.

5 commentaires

What is in the xls file? Is it image intensity values? Can you attach the workbook and tell me what cells you want to display as an image?
munah alhatmi
munah alhatmi le 28 Mar 2016
Modifié(e) : Walter Roberson le 28 Mar 2016
Thank you for reply..
actually i am working in image enhancement using matlab.
the excle file has the pixel values of result image.
my project has two parts:
first loading input image and enhanced by one of matlab filters then save the output image as excle file to use in next stage.
second stage is using genetic algorithm to reduce the mean sequare error to be much better than before. also, i am facing problem of display MSE & PSNR.
pleae see the attachements.
I would be too much thankful if you could help me.
There is no attachment.
Why does the image need to be saved to a file at all in between stages?
And if it does need to be saved, I can't find any reason at all to save it as an Excel workbook.
i don't know why doesn't attached.i had selected the file!
can i send it by email?
I saved in excel file because i want to do training for data. I don't have an idea about other ways because i am beginner in using matlab.
After you click Choose File, and Open, you have to click Attach File.
You can use imwrite to save the image
imwrite(yourImage, 'temporary image.png');
You can make the filename whatever you want instead of 'temporary image.png'. To read it back in:
rgbImage = imread('temporary image.png');

Connectez-vous pour commenter.

munah alhatmi
munah alhatmi le 29 Mar 2016
Dear Image Analyst,
i applied your method but the image appeared empty.
i feel the problem in passing the parameter.
i had attached my project.
my problem in second stage with MSE & PSNR and the resulted image.
i will appreciate your help.
many thanks,
munah alhatmi
munah alhatmi le 29 Mar 2016
the attachment of second stage ( genetic algorithm using machine learning)

2 commentaires

Dear friend
the better thing to do for your problem is to submit question on your question wall you will get many answers please do not use any question wall for your problem include me , this thing can be so efficient to got knowledge for all users , thanks to understand that
Dear ahmed..
thank you for your advice.
sure, i will do it.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by