Extracting Pixel Data from Images in Matlab

This week we ran through some more Matlab examples and also code from the Matlab forums to learn how to export the value of a jpg image to a .txt file. Below is code which both extracts the pixel values in rgb triads from a jpg image and places it in a .txt file, and then re-imports the data.[1]


%https://www.mathworks.com/matlabcentral/answers/52567-how-to-export-the-pixel-value-of-an-jpg-image-to-a-txt-file img = imread('ShorelineDJI_0040.JPG'); fid = fopen('deleteMeShoreline.txt', 'w'); if fid == -1, error('Cannot open file'); end fprintf(fid, '%d %d %d '); % Assuming it is an RGB image fprintf(fid, '%g ', img(:)); fclose(fid); fid = fopen('deleteMeShoreline.txt', 'r'); if fid == -1, error('Cannot open file'); end ImgSize = fscanf(fid, '%d %d %d ', 3); ImgData = fscanf(fid, '%g ', Inf); Img = reshape(ImgData, ImgSize); fclose(fid);

[1]https://www.mathworks.com/matlabcentral/answers/52567-how-to-export-the-pixel-value-of-an-jpg-image-to-a-txt-file



3 views

Recent Posts

See All

Get a Grip & Sailbot Sensors

Last week I helped Fred with the prototype 6 Degree of Freedom arm. We Figured out how to connect the transmitter and power to the arm. Now we've been focusing on tuning the controls to have a wider r

© 2013-2020 by UAS Academy - LASR@™, LASRlive™, T3™, and ATAP™ are Trademarks of UAS Academy