Extend the labels array to full 2D area

1 view (last 30 days)
AMEN BARGEES
AMEN BARGEES on 29 Jul 2022
Answered: Hari on 11 Sep 2023

I have a 2D data 460by950 and I reshaped it to 10by10by4370 and used it for Testing my network. The input is 10by10 matrix and the output is one label array 4370by1 categorical. I need to expand these labels to the original data size 460by950. data=reshape(data,10,10,[]); dim3= size(data,3); Label=[]; for i=1:dim3 YPred= classify(net,data(:,:,i)); Label=[Label;YPred]; end

  2 Comments
Benjamin Thompson
Benjamin Thompson on 29 Jul 2022
So reshape does not work to change to 460x950? Can you attach a file that defines the net and xx variables so that the Community can also run your sample code?
AMEN BARGEES
AMEN BARGEES on 29 Jul 2022
It can be reshaped to 46by95 but its something different, maybe because of the way I am using to input my data.

Sign in to comment.

Answers (1)

Hari
Hari on 11 Sep 2023
Hi Amen,
As per my understanding, you have a 2D data array with dimensions 460x950. You reshaped this array into a 3D array with dimensions 10x10x4370. You want to use this reshaped data for testing your network. The input to the network is a 10x10 matrix, and the output is a label array with dimensions 4370x1 (categorical). You need to expand these labels to match the original data size of 460x950.
From the line “Label=[Label;YPred];” in your code, I have seen that you are adding each of your prediction to the “Label vector each time. This creates a column vector of the predicted labels for the input 10x10 matrices but doesn’t expand the labels array to full 2D input. For the expansion of the Labels, you can userepmat” function in MATLAB.
Expanded_label = repmat(YPred, 46, 95); % Expand labels to match original size
After predicting the label for each input matrix, use the “repmat” function to expand the predicted label “YPred”. By repeating the label 46 times vertically and 95 times horizontally, we can match the original data size of 460x950. This ensures that each element in the expanded Label array corresponds to the predicted label for the corresponding element in the original data.
Refer to the below documentation to learn more about “repmat” function in MATLAB.

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!