Azzera filtri
Azzera filtri

Struct to double conversion

33 visualizzazioni (ultimi 30 giorni)
Tousif Ahmed
Tousif Ahmed il 13 Apr 2017
I have 59 images in a file and when i am running it, it shows "59x1 struct" but i need to convert it into double format which i need it. Can anyone please help me to do that.
  11 Commenti
Stephen23
Stephen23 il 14 Apr 2017
Modificato: Stephen23 il 14 Apr 2017
I know that you want a double array. But you have not answered my question about the dimensions that you want the double array to have. I will ask once more:
The images are (most likely) 3D. How many dimensions do you want the double array to have? Or, put another way, how do you want the images arranged relative to one-another?
Tousif Ahmed
Tousif Ahmed il 14 Apr 2017
i want training images to be in this 3x178.. like this are you asking?

Accedi per commentare.

Risposte (2)

Saurabh
Saurabh il 28 Mag 2023
To convert a struct of 59 images to a double format, you will need to loop over each image and convert it by calling the im2double() function. Here's some sample code:
% Assuming your struct of images is called "images"
num_images = length(images);
double_images = cell(1,num_images);
for i = 1:num_images
double_images{i} = im2double(images(i).data);
end

Parag Jhunjhunwala
Parag Jhunjhunwala il 9 Giu 2023
Modificato: Parag Jhunjhunwala il 9 Giu 2023
There are 2 ways of converting an image to double format:
1. Using im2double() function:
double_images=[];
for i=1:length(images)
img = imread(images{i}); % read the image
double_images(i) = im2double(img); % convert the image to double
end
2. Using double() function:
double_images=[];
for i=1:length(images)
img = imread(images{i}); % read the image
double_images(i) = double(img); % convert the image to double
end
Both of these methods convert an image to a double-precision array, but the main difference is that im2double() function scales the output range to [0,1] while double() function keeps the original dynamic range of the input image.

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by