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

ES
ES 2017년 4월 13일
Running what?
Stephen23
Stephen23 2017년 4월 13일
편집: Stephen23 2017년 4월 13일
Tousif Ahmed
Tousif Ahmed 2017년 4월 14일
Running the code, myDir = 'face/'; ext_img= '*.jpg'; x = dir([myDir ext_img]); The images are in the face folder from which i am accessing. When i am running the above code, the images are stored in x with 59 images and looks like this. x= 59x1 struct. I need to change it to double format. Hope you are understanding the question
Stephen23
Stephen23 2017년 4월 14일
편집: Stephen23 2017년 4월 14일
Images are usually 3D arrays. You have 59 of them. You want them merged into one 4D array? What is the problem with accessing them in the structure? The data is already there.
Tousif Ahmed
Tousif Ahmed 2017년 4월 14일
I need to use the neural network and i am taking these 59 images as training images, so while training i am getting error. The images should be in double format as i am using the default "Wine Classification".
Stephen23
Stephen23 2017년 4월 14일
편집: Stephen23 2023년 5월 29일
If this is your code:
x = dir([myDir ext_img]);
then x does not contain image data at all, but is a structure of file information. I wold suggest that you start by actually doing some reading about dir (which does not load image data at all, as you will find out when you read its documentation).
Then you should search this forum for importing images in a loop. You will find many useful threads, e.g.:
Tousif Ahmed
Tousif Ahmed 2017년 4월 14일
if you know how to read the 59 images in double format, it will be of great help to me
Stephen23
Stephen23 2017년 4월 14일
편집: Stephen23 2017년 4월 14일
@Tousif Ahmed: I already gave you a link that explains exactly how to import images in a loop, and shows example code too. Did you read the link that I gave you?
Tousif Ahmed
Tousif Ahmed 2017년 4월 14일
Yes i saw the link,jpeg files in struct but for the neural network i need in double.
Stephen23
Stephen23 2017년 4월 14일
편집: Stephen23 2017년 4월 14일
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 2017년 4월 14일
i want training images to be in this 3x178.. like this are you asking?

댓글을 달려면 로그인하십시오.

답변 (2개)

Saurabh
Saurabh 2023년 5월 28일

1 개 추천

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 2023년 6월 9일
편집: Parag Jhunjhunwala 2023년 6월 9일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2017년 4월 13일

편집:

2023년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by