Applying Regression Model results on multispectral image

I used the regression learner application to develop a regression model. Then exported the model to the workspace.
I want to apply the exported model on a multispectral image.
I used foor loop to convert the image to table and apply the model. it works but it took very long time. I believe there is much faster way.
My code:
B = My_image;
a = size (B,1);
b = size (B,2);
c = size (B,3);
D = zeros(a,b);
l=0;
for i = 1:a
for j = 1:b
S.B01 = B(i,j,1);
S.B05 = B(i,j,5);
S.B06 = B(i,j,6);
S.B07 = B(i,j,7);
S.B09 = B(i,j,9);
S.B10 = B(i,j,10);
S.B11 = B(i,j,11);
S.B12 = B(i,j,12);
S.B02 = B(i,j,2);
S.B03 = B(i,j,3);
S.B04 = B(i,j,4);
S.B08 = B(i,j,8);
S.B8a = B(i,j,13);
TT = struct2table( S );
l = FDT.predictFcn(TT);
D (i,j) = l;
end
end
May anyone help me in that
Thank You

Answers (1)

Hi Nagwa,
I understand that you want to convert a multispectral image to a table, so that it can be used in the regression model. Instead of using a nested loop to convert each pixel of the image to a table and apply the model, you can vectorize the process as vectorized code often runs much faster than the corresponding code containing loops.
For more information on vectorization, you can refer to the following documentation link:
Hope this helps!

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 20 Sep 2022

Answered:

on 6 Sep 2023

Community Treasure Hunt

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

Start Hunting!