how to use multibandread function for multiple image raw data in a for loop
5 次查看(过去 30 天)
显示 更早的评论
for k=1:datasetname_num
x= dataset_name(k,:);
raw_data_headfile(k,:) = strcat('D:\HSI_data\chaitanya\normal\',x,'\capture\',x, '.hdr')
raw_data_datafile(k,:) = strcat('D:\HSI_data\chaitanya\normal\',x,'\capture\',x, '.raw')
raw_info(k,:) = enviinfo(raw_data_headfile(k,:))
% raw_data = multibandread(raw_data_datafile(1,:),[raw_info(1,:).Height(1,:), raw_info(1,:).Width(1,:), raw_info(1,:).Bands(1,:)],raw_info(1,:).DataType(1,:), raw_info(1,:).HeaderOffset(1,:), raw_info(1,:).Interleave(1,:), raw_info(1,:).ByteOrder(1,:));
raw_data(:,:,:) = multibandread(raw_data_datafile(k,:),[raw_info(k,:).Height(k,:), raw_info(k,:).Width(k,:), raw_info(k,:).Bands(k,:)],raw_info(k,:).DataType(k,:), raw_info(k,:).HeaderOffset(k,:), raw_info(k,:).Interleave(k,:), raw_info(k,:).ByteOrder(k,:));
end
this is the code i used and the errors are as follows:
Unable to perform assignment because the size of the left side is 879-by-1024-by-448 and the size of the right side is 851-by-1024-by-448.
Error in normal_breast22 (line 38)
raw_data(:,:,:) = multibandread(raw_data_datafile(1,:),[raw_info(1,:).Height(1,:), raw_info(1,:).Width(1,:),
raw_info(1,:).Bands(1,:)],...
Index in position 1 exceeds array bounds. Index must not exceed 1.
Error in normal_breast22 (line 41)
raw_data(:,:,:) = multibandread(raw_data_datafile(k,:),[raw_info(k,:).Height(k,:), raw_info(k,:).Width(k,:),
raw_info(k,:).Bands(k,:)],...
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in normal_breast22 (line 38)
raw_data(k,:,:) = multibandread(raw_data_datafile(k,:),[raw_info(k,:).Height, raw_info(k,:).Width, raw_info(k,:).Bands],...
please someone help me with the code.
0 个评论
回答(1 个)
Manasa Singam
2022-12-1
I strongly believe that you are trying to concatenate arrays of different size, because of that you are getting the error saying:
Unable to perform assignment because the size of the left side is 879-by-1024-by-448 and the size of the right side is 851-by-1024-by-448.
I suggest you use cell array since the datacube are of different size.
raw_data = cell(datasetname_num,1); %Initialize the raw_data with cell array
for k=1: datasetname_num
x= dataset_name(k,:);
raw_data_headfile(k,:) = strcat('D:\HSI_data\chaitanya\normal\',x,'\capture\',x, '.hdr')
raw_data_datafile(k,:) = strcat('D:\HSI_data\chaitanya\normal\',x,'\capture\',x, '.raw')
raw_info(k,:) = enviinfo(raw_data_headfile(k,:))
data = multibandread(raw_data_datafile(k,:),[raw_info(k,:).Height(k,:), raw_info(k,:).Width(k,:), raw_info(k,:).Bands(k,:)],raw_info(k,:).DataType(k,:), raw_info(k,:).HeaderOffset(k,:), raw_info(k,:).Interleave(k,:), raw_info(k,:).ByteOrder(k,:))
raw_data{k} = data; % Can concatenate data with different size
end
But I strongly suggest for you to use hypercube if you have hyperspectral package, it is very easy to understand and write above code using hypercube. Enable commented lines, if the data is of different size.
raw_data = []; % If the data is of same size
% raw_data = cell(datasetname_name) % If the data is of different size
for k=1:datasetname_num
x= dataset_name(k,:);
raw_data_headfile(k,:) = strcat('D:\HSI_data\chaitanya\normal\',x,'\capture\',x, '.hdr')
raw_data_datafile(k,:) = strcat('D:\HSI_data\chaitanya\normal\',x,'\capture\',x, '.raw')
% doesn't need to enviinfo, multibandread which needs multiple inputs
% to pass, just passing file names to hypercube will take care of
% everything.
hcube = hypercube(raw_data_datafile(k,:),raw_data_headfile(k,:));
raw_data = cat(3,raw_data,hcube.DataCube); % If the data is of same size
% raw_data{k} = hcube.DataCube; % if the data is of different size
end
Let us know, if you still face any issues.
Thanks!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!