saving elements of a dataset as images (2025)

23 views (last 30 days)

Show older comments

imaging on 16 Jul 2024 at 12:59

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images

Answered: Image Analyst about 2 hours ago

Open in MATLAB Online

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

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

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (2)

Muskan about 23 hours ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images#answer_1486276

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images#answer_1486276

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:

  1. 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.
  2. 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

1 Comment

Show -1 older commentsHide -1 older comments

imaging about 23 hours ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images#comment_3212792

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images#comment_3212792

thanks a lot for your help.

Sign in to comment.

Image Analyst 2 minutes ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images#answer_1486947

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2137673-saving-elements-of-a-dataset-as-images#answer_1486947

Open in MATLAB Online

You want to save inputData(:,:,idxSelected(i)), which is a variable internal to a Mathworks written function called loadCSIDataset. Not exactly sure what that function is but we recommend never changing a built-in function from a Toolbox written by the Mathworks.

What you should do is to make a copy of that function in the current folder, or a folder of your own earlier in the search path, with a different name, like myLoadCSIDataset.m. Then you will modify your copy, not the original function.

Then in the for loop you can construct a filename with sprintf and fullfile and then save the image slice with imwrite. Here is a snippet with the relevant part that you should modify.

% Define the name of the output folder where you want to save these images.

outputFolder = 'C:\whatever'; % TODO: CHANGE THIS LINE.

if ~isfolder(outputFolder)

mkdir(outputFolder);

end

% Plot 1 - CSI image

for k = 1 : numPlots % Use k instead of i (the imaginary constant) as an iteration variable.

sliceNumber = idxSelected(k);

nexttile

imagesc(inputData(:, :, sliceNumber));

colorbar;

xlabel('Packets');

ylabel('Subcarriers');

caption = sprintf('Raw CSI (Slice #%d))', sliceNumber);

title(caption, 'FontSize', 18);

drawnow; % Force it to update the screen display immediately.

% Now make output file name for a lossless compression PNG format file.

baseFileName = sprintf('Slice %3.3d.png', sliceNumber);

fullFileName = fullfile(outputFolder, baseFileName); % Prepend output folder.

% Now save this image slice to disk.

imwrite(inputData(:, :, sliceNumber), fullFileName) % Save to disk.

fprintf('On iteration %d, saved slice #%d as %s.\n', k, sliceNumber, fullFileName); % Print the progress to the command window.

end

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsImagesConvert Image Type

Find more on Convert Image Type in Help Center and File Exchange

Tags

  • datasets
  • elements
  • images

Products

  • MATLAB

Release

R2024a

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


saving elements of a dataset as images (5)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

saving elements of a dataset as images (2025)

FAQs

How many images for a good dataset? ›

While there's no fixed rule, a general guideline suggests having at least hundreds to thousands of images per class for effective learning. The adequacy of the training dataset depends on the complexity of the classification task.

What are the elements of a dataset? ›

Elements are the individual fields that exist within groups upon pages within the dataset. As such, they are the most granular piece of data in the dataset and you want to make any edits to your dataset before updating your template to match. (This should not be done in the reverse.)

How to prepare image dataset for machine learning? ›

Steps
  1. Gather images for your dataset.
  2. Rename the pictures according to their classes.
  3. Merge them into one folder.
  4. Resize the pictures.
  5. Convert all images into the same file format.
  6. Convert images into a CSV file.
  7. A few tweaks to the CSV file.
  8. Load the CSV (BONUS)

Where to store large image datasets? ›

As the volume of image datasets increases, leveraging cloud storage remains crucial for managing and storing large files while maintaining data security and accessibility.

How big should an image dataset be? ›

It can be complicated to determine the number of images needed in your Image Dataset for an Image Classification task. However, there are some good rules of thumb that you can follow. According to one of them, around 1000 examples by class are a decent amount to start with.

How many images are enough for object detection? ›

Object detection

The data set must contain at least five images that have an object that is labeled for each defined object. For example, if you want to train the data set to recognize cars, you must add the car label to at least five images.

What are the 4 elements of data? ›

Four Elements of Data: Volume, velocity, variety, and veracity
  • Volume is how much data you are actually managing.
  • Velocity is how fast that data is being created or being changed.
  • Variety is how much different data is being collected.
  • Veracity is how “clean” the data is.

What is an example of a data element? ›

A basic unit of information that has a unique meaning and subcategories (data items) of distinct value. Examples of data elements include gender, race, and geographic location. The smallest named item of data that conveys meaningful information.

What are the three main components of dataset? ›

The dataset consists of three main parts: (1) Metadata; (2) UI events; (3) Network traces. Metadata includes the network type (cellular or WiFi), information of GPS, network names and signal strength.

What makes a good image dataset? ›

For real-world use cases we recommend images from different times of day, different seasons, different weather, different lighting, different angles, different sources (scraped online, collected locally, different cameras) etc. Label consistency. All instances of all classes in all images must be labelled.

How do I upload an image to a dataset? ›

Select Create to create the empty dataset. After selecting Create you will advance to the data import window. Select the radio_button_checkedSelect import files from Cloud Storage and specify the Cloud Storage URI of the CSV file with the image location and label data.

How many images needed for machine learning? ›

Usually around 100 images are sufficient to train a class. If the images in a class are very similar, fewer images might be sufficient. the training images are representative of the variation typically found within the class.

How to efficiently store images in a database? ›

There are several ways to store images in a database, including as binary data, file paths, or using cloud storage. The best method depends on the specific requirements and constraints of the project.

How do I save a large dataset? ›

When storing large data sets, it's important to use a storage format that is designed to handle large data sets efficiently. Two such formats are Parquet and HDF5. These are columnar storage formats that allow you to store and retrieve data in a compressed and optimized format.

What is considered a good data set? ›

A good data set is one you can use

As long as you can understand the data set and it has the information you need, even a small data set can pack a punch for analysis. Smaller data sets are also easy to store, share, and publish, and are likely to perform well.

How many images do you need for classification? ›

Usually around 100 images are sufficient to train a class. If the images in a class are very similar, fewer images might be sufficient. the training images are representative of the variation typically found within the class.

What is the recommended dataset size? ›

The 10 times rule is a useful starting heuristic for estimating dataset sizes in machine learning. It recommends having at least 10 examples for each feature or predictor variable in your model.

How many images are needed for stacking? ›

How many images do you need? That really depends on your scene/subject. Most focus-stacked landscapes require just two or three shots (one for the foreground and one for the background, or one each for the foreground, middleground, and background).

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 5263

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.