필터 지우기
필터 지우기

How to convert image to array and save it in a text file?

조회 수: 15 (최근 30일)
Ali Purse
Ali Purse 2018년 10월 18일
답변: Image Analyst 2018년 10월 18일
I want to save an image's array to a text file in order to show it again.
But I don't know how to store it in right conditions.
I'm using the following code:
I = imread('image.jpg');
image=mat2gray(I);
imshow(image);
FID = fopen('FileName.txt', 'w');
if FID == -1, error('Cannot create file.'); end
fprintf(FID, '%f \n', image);
fclose(FID);

채택된 답변

madhan ravi
madhan ravi 2018년 10월 18일
dlmwrite('FileName.txt',image)

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 10월 18일
Do not use image as the name of your variable because it's the name of a built in function.
See attached demo that will take a color image and write a text file in the form
r, g, b, x, y
One row for every pixel.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by