I'm trying to make an image with data from a .txt file

2 visualizaciones (últimos 30 días)
silvia cano
silvia cano el 14 de Ag. de 2023
Comentada: Image Analyst el 14 de Ag. de 2023
I have a data 80 lines by 10 columns, and I want to make an image with this data
How can I generate an image from a data set?

Respuestas (3)

Voss
Voss el 14 de Ag. de 2023
M = readmatrix('data.txt');
imshow(M)
  3 comentarios
Voss
Voss el 14 de Ag. de 2023
M = readmatrix('data_face.txt');
figure
imshow(M,[])
figure
imshow(M.',[])

Iniciar sesión para comentar.


Star Strider
Star Strider el 14 de Ag. de 2023
Editada: Star Strider el 14 de Ag. de 2023
Use readmatrix to read the file.
To display the image, then do something like this —
% writematrix(rand(80,10),'YourFile.txt') % Create Data (Omit This Step, Since You Already HAve A Text File)
Data = readmatrix('data_face.txt') % Read File
Data = 67×6
1.0e+09 * 0.5419 1.9369 0.5441 1.6319 1.1765 0.1744 1.2969 0.9786 1.6843 1.8360 1.9534 1.7013 1.2254 1.3803 1.4313 0.9776 1.8183 1.3932 1.0956 0.5407 0.8258 0.8758 0.8759 1.1639 1.2794 1.1295 1.1628 1.2124 1.1620 1.9181 1.2757 1.2293 1.3803 0.8085 1.3932 1.3138 1.2813 1.2796 1.5288 1.9199 1.6664 1.7017 0.5398 1.8354 0.5435 1.8519 0.6618 1.3308 1.0962 1.1633 1.3302 0.8410 0.8251 1.2793 1.0959 1.3138 1.0959 0.5407 1.7692 1.9537
Data = log2(Data)
Data = 67×6
29.0134 30.8511 29.0193 30.6039 30.1319 27.3780 30.2724 29.8661 30.6495 30.7739 30.8633 30.6640 30.1906 30.3623 30.4147 29.8647 30.7600 30.3757 30.0291 29.0102 29.6212 29.7061 29.7062 30.1163 30.2528 30.0731 30.1149 30.1752 30.1140 30.8370 30.2487 30.1952 30.3623 29.5907 30.3757 30.2910 30.2550 30.2531 30.5098 30.8384 30.6341 30.6644 29.0078 30.7734 29.0178 30.7863 29.3018 30.3097 30.0299 30.1156 30.3090 29.6475 29.6200 30.2528 30.0295 30.2911 30.0295 29.0102 30.7205 30.8636
figure
surf(Data) % Use 'imagesc' To Display It (Consider Other Options As WEll)
% axis('square') % Optional (Consider Other Options As Well)
colormap(turbo) % Choose Appropriate Colormap
% view(0,90)
See the documentation on imagesc, axis, and colormap for details on those functions.
EDIT —
Is it encrypted or something? I also tried surf and contour and a log2 transformation and could not get a reasonable reasult.
.
  2 comentarios
silvia cano
silvia cano el 14 de Ag. de 2023
thats a plot of data ? but you can generate and image with data_face.txt file?
Star Strider
Star Strider el 14 de Ag. de 2023
Nothing I have tried helps with this.
Data = readmatrix('data_face.txt'); % Read File
figure
imagesc(Data)
axis('equal')
colormap(gray)
Datar = imresize(Data, 5, 'bilinear');
figure
imagesc(Datar)
colormap(gray)
axis('equal')
Datar = interp2(Data, 5, 'makima');
figure
imagesc(Datar)
colormap(gray)
axis('equal')
.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 14 de Ag. de 2023
I get this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%--------------------------------------------------------------------------------------------------------
% READ IN TEST IMAGE
folder = [];
baseFileName = 'data_face.txt';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = readmatrix(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
rows = 67
columns = 6
numberOfColorChannels = 1
%--------------------------------------------------------------------------------------------------------
% Display the image.
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
I do not get a face of a woman like you do. Perhaps you attached the wrong data file. The file you attached has only 67 rows and 6 columns, not 80 rows and 10 columns.
  3 comentarios
silvia cano
silvia cano el 14 de Ag. de 2023
is my imagination on the middle look like two eyes

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by