I have the following function:
function rgbMap = thresholdFunction(x)
rArray=zeros(size(numel(x)));
gArray=zeros(size(numel(x)));
bArray=zeros(size(numel(x)));
rArray(x>110 & x<=152) = 255;
gArray(x<=110) = 255;
bArray(x>152) = 255;
rgbMap = cat(3,rArray,gArray,bArray);
end
Which then gives the error message: 'Dimensions being concatenated are not consistent'
The function is designed to apply thresholds to a grayscale image which is the input 'x', and give a colormap of the different value selections 'rgbMap'.
The reason I'm using a function instead of applying the thresholds directly to the image, is because it's part of a batch processing code, and so 'x' would end up being more than one image being put through a 'for' loop.
I am fairly new to Matlab so if I'm doing something ridiculously stupid, feel free to point it out!

 Réponse acceptée

Geoff Hayes
Geoff Hayes le 26 Avr 2017
Modifié(e) : Geoff Hayes le 26 Avr 2017
Andrew - look at the line
rArray=zeros(size(numel(x)));
numel returns the number of elements in x so this could be (for example) 42 which is a 1x1 scalar. Finding the size of this scalar will be
>> size(42)
ans =
1 1
and so all of your arrays will be 1x1. Just remove the numel from each of your array initializations so that the arrays are of the same dimension/size as the two-dimensional x.
Note that the error is occurring because while each of your arrays begin as 1x1 arrays, their updates with
rArray(x>110 & x<=152) = 255;
% etc.
will not guarantee that each of the three has the same dimension (even if they did, this is not the answer you want) and so you end up trying to concatenate three matrices of different dimensions.

1 commentaire

Andrew McLean
Andrew McLean le 26 Avr 2017
Knew it would be something like that, thanks for the answer

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by