How to extract pixel intensity of a grayscale image (*.jpg) to a MS Excel table

12 ビュー (過去 30 日間)
Mac
Mac 2024 年 9 月 16 日
コメント済み: Mac 2024 年 9 月 16 日
Hello everyone, I am a very new beginner with image processing and Mathlab. Please help me with the following isse, many thanks in advance !
I have a grayscale image. I'd like to extract its pixel intensities to a MS Excel table with three vectors, including pixel intensiy, X and Y coordinates of the pixel.

採用された回答

Sameer
Sameer 2024 年 9 月 16 日
編集済み: Sameer 2024 年 9 月 16 日
Hi Mac
From my understanding, you want to extract pixel intensities from a grayscale image and save them in an 'MS Excel' table with the corresponding X and Y coordinates.
Here’s how you can achieve it:
1. Read the Image: First, ensure your grayscale image is accessible, either in the current directory or by providing the full path.
% Read the grayscale image
img = imread('your_image.jpg');
2. Extract Pixel Intensities and Coordinates: Loop through each pixel to gather intensity values and their coordinates.
% Get the size of the image
[rows, cols] = size(img);
% Initialize vectors for storing pixel data
pixelIntensity = [];
xCoordinates = [];
yCoordinates = [];
% Loop through each pixel
for x = 1:cols
for y = 1:rows
% Append data to vectors
pixelIntensity = [pixelIntensity; img(y, x)];
xCoordinates = [xCoordinates; x];
yCoordinates = [yCoordinates; y];
end
end
3. Write Data to Excel: Utilize "writetable" function to save the extracted data into an Excel file.
% Create a table from the vectors
dataTable = table(xCoordinates, yCoordinates, pixelIntensity, ...
'VariableNames', {'X', 'Y', 'Intensity'});
% Write the table to an Excel file
writetable(dataTable, 'pixel_data.xlsx');
Please refer to the below MathWorks documentation link:
Hope this helps!
  3 件のコメント
Sameer
Sameer 2024 年 9 月 16 日
Edited, Thanks!
Mac
Mac 2024 年 9 月 16 日
It works very well. I really appreciate.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2024 年 9 月 16 日
See my attached demo that writes an image out to a CSV text file that can be read in by Excel.

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by