I'm trying to make an image with data from a .txt file
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
2 commentaires
Réponses (3)
Star Strider
le 14 Août 2023
Modifié(e) : Star Strider
le 14 Août 2023
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 = log2(Data)
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)
EDIT —
Is it encrypted or something? I also tried surf and contour and a log2 transformation and could not get a reasonable reasult.
.
2 commentaires
Star Strider
le 14 Août 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')
.
Image Analyst
le 14 Août 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)
%--------------------------------------------------------------------------------------------------------
% 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.
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!