saving elements of a dataset as images
Show older comments
hello i would like to ask how to save inputData(:,:,idxSelected(i)) as an image file. thanks very much.
function [data,labelsVec,timestamps] = loadCSIDataset(fileName,label,visualizeData)
% loadCSIDataset Loads and visualizes the pre-recorded CSI dataset
% [DATA,LABELSVEC,TIMESTAMPS] =
% loadCSIDataset(FILENAME,LABEL,VISUALIZEDATA) loads the dataset that
% contains the data with the label (LABEL). Pre-recorded CSIs are
% visualized if (VISUALIZEDATA) is true. The function returns the
% pre-recorded beacon frame CSI (DATA), related timestamps (TIMESTAMPS),
% and the categorical labels vector (LABELSVEC).
% Copyright 2022-2024 The MathWorks, Inc.
arguments
fileName {char,string}
label (1,1) string
visualizeData = true;
end
% Load the pre-recorded dataset
datasetDir = which(fileName);
loadedData = load(datasetDir);
data = loadedData.data;
labelsVec = categorical(repmat(label,size(data,ndims(data)),1));
timestamps = loadedData.timestamps;
disp(['Dimensions of the ' char(label) ' dataset (numSubcarriers x numPackets x numCaptures): ' '[' num2str(size(data)) ']'])
% Visualize the dataset
if visualizeData
plotSamplesFromDataset(data,label);
end
% Plot samples from the pre-recorded dataset
function plotSamplesFromDataset(data,mode)
% Plot at most three random samples of the dataset
inputData = abs(data); % Visualize only the magnitude of the CSI
numTotalCaptures = size(inputData,ndims(inputData));
numPlots = min(3,numTotalCaptures);
idxSelected = sort(randperm(numTotalCaptures,numPlots));
figure;
T = tiledlayout(2,numPlots,'TileSpacing','compact');
% Plot 1 - CSI image
for i = 1:numPlots
nexttile
imagesc(inputData(:,:,idxSelected(i)));
colorbar;
xlabel('Packets');
ylabel('Subcarriers');
title(['Raw CSI (#' num2str(idxSelected(i)),')']);
end
% Plot 2 - Normalized CSI periodogram
for j = 1:numPlots
nexttile
imagesc(csi2periodogram(inputData(:,:,idxSelected(j))));
colorbar;
clim([0 1]);
xlabel('Temporal Index');
ylabel('Spatial Index');
title(['CSI Periodogram (#' num2str(idxSelected(j)),')']);
title(T,['Randomly Selected Samples of "', char(mode) '" Data']);
set(gcf,'Position',[0 0 650 450]);
end
end
end
Accepted Answer
More Answers (2)
Muskan
on 16 Jul 2024
1 vote
Hi,
As per my understanding, to save the "inputData(:,:,idxSelected(i)") as an image file, you can use MATLAB's "imwrite" function. This function writes an image to a file in various formats such as PNG, JPEG, TIFF, etc.
You can follow the following steps:
- Convert the Data to a Suitable Format: Ensure the data is in a format that "imwrite" can handle. Typically, this means converting the data to "uint8" or "double" and normalizing it if necessary.
- Save the Image: Use "imwrite" to save the image.
You can also refer to the following documentation of "imwrite" for a better understanding: https://www.mathworks.com/help/matlab/ref/imwrite.html
Image Analyst
on 19 Jul 2024
1 vote
Your cRadon() will do the radon transform for every angle from 1,2,3,4,....,179,180. Is that what you want or do you want just the single angle of 180 degrees for one projection only?
5 Comments
Image Analyst
on 21 Jul 2024
Try sprintf
caption = sprintf('Randomly Selected Samples of %s Data.', mode);
title(caption)
What is variable type is mode?
whos mode
mode is a built-in function so you should not use the name of a built-in function for your variable names. Pick another name for it.
imaging
on 21 Jul 2024
Image Analyst
on 22 Jul 2024
If my Answer solves your original question, then could you please click the "Accept this answer" link to award me with "reputation points" for their efforts in helping you? I'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
imaging
on 23 Jul 2024
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!