How to save an image loaded in matlab in excel? file

35 vues (au cours des 30 derniers jours)
Srikar Malyala
Srikar Malyala le 23 Mai 2020
Modifié(e) : Image Analyst le 23 Mai 2020
I am doing image processing in MATLAB.I want to store the filtered images and original image into excel file along with their PSNR values for comparision without saving the processed images into my drive.
My problem here is to display the image matrix in excel as an image.But if I am trying to use xlswrite() it writes individual pixel and if I cannot use the Excel ActiveX command as shown here because it works with image path
Please help me in fixing this issue.

Réponse acceptée

Image Analyst
Image Analyst le 23 Mai 2020
Modifié(e) : Image Analyst le 23 Mai 2020
See this demo to paste axes onto Excel, and adapt as needed. First you need to get an ActiveX handle to Excel (Windows only):
% Open the workbook in Excel using ActiveX.
Excel = actxserver('Excel.Application');
excelWorkbook = Excel.workbooks.Open(excelFullFileName);
Excel.Visible = true; % Make it visible.
Then save your picture with exportgraphics(), imwrite(), or export_fig() and call this function to read the image file and paste into Excel.
%=========================================================================================================================================================
% Looks for a picture file on disk, and if it's there, paste the picture file onto the specified sheet.
function PasteImageOntoExcelSheet(Excel, sheetName, pictureFileName)
try
if ~isfile(pictureFileName)
warningMessage = sprintf('Pciture file not found:\n%s\nso we cannot paste it into Excel', pictureFileName);
uiwait(warndlg(warningMessage));
return;
end
Sheets = Excel.sheets;
% Excel.Visible = true;
foundSheet = false;
for sheetIndex = 1 : Sheets.count
% Activate the worksheet. (Perhaps unnecessary.)
% worksheets.Item(sheetIndex).Activate;
% Get the name of the worksheet with this sheet index.
thisName = Sheets.Item(sheetIndex).Name;
if strcmpi(thisName, sheetName)
% We found the sheet to paste onto.
Sheets.Item(sheetIndex).Activate;
currentSheet = Excel.ActiveSheet;
% Get a handle to Shapes for the Sheet
Shapes = currentSheet.Shapes;
% Add image by importing one from an image file on disk. Place at a certain position. Last 4 arguments are : x, y, width, height.
Shapes.AddPicture(pictureFileName, 0, 1, 300, 20, 1000, 480);
foundSheet = true;
break;
end
end
if foundSheet
return;
end
% If we get here, a sheet by the requested name was not found so we need to make it.
% warningMessage = sprintf('No sheeet with name %s found in the workbook', sheetName);
% uiwait(warndlg(warningMessage));
% The new sheet is inserted before the active sheet.
Sheets.Item(3).Activate; % Activate sheet 3.
Excel.ActiveWorkbook.Sheets.Add;
Excel.ActiveWorkbook.ActiveSheet.Name = sheetName;
% Get a handle to Shapes for the Sheet
Shapes = Excel.ActiveSheet.Shapes;
% Add image by importing one from an image file on disk. Place at a certain position. Last 4 arguments are : x, y, width, height.
Shapes.AddPicture(pictureFileName, 0, 1, 300, 20, 1000, 480);
catch ME
% Some error happened if you get here.
errorMessage = GetErrorMessage(ME); % Get error message with call traceback and file's date.
WarnUser(errorMessage); % Pop up error message to show user what it is. Also prints to command window or console window (if program is an executable).
end
return; % from PasteImagesOntoExcelSheet

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by