How to create two different sets of images from one set of images using indexing?

3 vues (au cours des 30 derniers jours)
Sweta
Sweta le 5 Août 2022
Commenté : Sweta le 18 Août 2022
I have a set of 100 images with dimensions 1000×500×100 where 100 is pixel per A- line, 500 lines per frame. Lets say I index them in code using i = 1:100. So I need to make two stacks of images one having i=1,2 is in stack 1 then i=3,4 goes in stack 2. Then again i =5,6 goes in stack 1 and then i=7,8 goes in stack 2. This way i want to distribuyte the hundred images. The code I use to aquire the images is shared below.
Thank You for helping me.
tic, clear all; close all; clc;
Adrs=uigetdir('\.','Select Folder for Phase image');
file_name=dir(fullfile(Adrs,'*.bmp'));
total_num=numel(file_name);
h = waitbar(0,'Reading Phase image files.... Please Wait');
for I=1:total_num
file1=fullfile(Adrs,file_name(I).name);
img_phs(:,:,I)=(imread(file1));
waitbar(I/total_num,h);
end
close(h)

Réponse acceptée

Rohit
Rohit le 8 Août 2022
Example:
I am assuming the “data” to be consisting of 10 frames of 5*5 black and white images and then I distribute them into 2 sets (“set1”, ”set2”) based on indexing. The code for the same is below:
Code:
data=randi(20,5,5,10);
frame=data(:,:,1);
Indexing frames
index1=[1,2,5,6,9,10];
set1=data(:,:,index1);
index2=[3,4,7,8];
set2=data(:,:,index2);
Below is the documentation to help with array and matrices creation and manipulation:
  1 commentaire
Sweta
Sweta le 18 Août 2022
Thank You so much Rohit for getting back to me , but for huge stacks of images like 200 or 300 images , I can write all the index numbers, also if want to take every 3rd alternative image instead of one alternative image, this function wont be applicable. Thats why I need more dynamic code with variables where I can put the no. of total frames and just put the index by which I need seperation.....like "3" i.e. first 3 images in stack 1 then next three images in stack 3.
Thank you again for your help and your time

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing 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!

Translated by