How can I use indexed image in neural network ?

I have converted RGB images into indexed images using function rgb2ind then I made their matrix and load it using the code
fprintf('Loading and Visualizing Data ...\n')
load('ClothingData.mat');
m = size(X, 1);
[sel] = randperm(size(X, 1)); % Randomly select 100 data points to display
sel = sel(1:100);
displayData(X(sel, :));
but it is throwing this error message
Warning: Size vector should be a
row vector with integer elements.
> In displayData at 30
In ex4 at 50
Error using reshape
Size arguments must be real
integers.
Please tell me how to fix this error, also can I use indexed images for neural network classification or not

2 Comments

displayData does not appear to be a Mathworks routine, and also does not appear to be part of the File Exchange.

Sign in to comment.

 Accepted Answer

"can I use indexed images for neural network classification or no"
Yes.
If you are doing pattern matching, you might even get a useful result. But don't expect anything useful even for pattern matching unless you passed a fixed colormap into rgb2ind(). And even in that case, if you did not do illumination correction, your results might be low quality.

13 Comments

For https://github.com/aptiva0985/MachineLearning-Andrew-Ng-Coursera-/blob/master/ML003/mlclass-ex3/displayData.m if you do not pass a second parameter, then the number of elements you pass in must be the square of an integer.
my image dimension is 64 x 94. Do you mean I should use square image like 100 x 100 or 60 x 60 ?
Yes. However you might find it easier to just pass in the width of your image as the second parameter. The problem only occurs if you omit the second parameter.
By using squared images it is displaying data but not all of data is showing. Most of elements are missing moreover it is grayscale but my images are quantized.
Call colormap() passing in the appropriate colormap array after you call displayData()
% Load Training Data
fprintf('Loading and Visualizing Data ...\n')
% load('myclothingdata.mat');
load('myclothingdata.mat');
m = size(X, 1);
% Randomly select 100 data points to display
[sel] = randperm(size(X, 1));
sel = sel(1:100);
displayData(X(sel, :));
colormap()
fprintf('Program paused. Press enter to continue.\n');
Dear I have called colormap() after calling displaydata() but it is not working, still showing grayscale images. Please tell where is the proper place to write this function and how? thanks
You do not pass in the name of a color map. You indicated that these are indexed images, so somewhere you must have an array that relates X values to color: you need to colormap() that array.
Sorry I don't know how to make a colormap() array and relate it to my indexed images which are contained in X. Can you guide me as I am new in Matlab. thanks
What does "indexed image" mean to you? If one of the pixels has value (say) 4, then what color should the pixel be?
Please show the output of
whos -file myclothingdata.mat
According to my understanding we should have two matrices
  • First should contain our indexed images called X
  • Other should be a colormap matrix map containing floating-point values in the range [0, 1].
For now I have just X matrix(vector) which contains my indexed images.
(detail) Actually I converted my original RGB images of clothes into indexed images using rgb2ind function of matlab and saved all these indexed images in a separate folder. In next step I made the vector X of all these indexed images. Now whenever I try to display my indexed images data using DisplayData (a custom function) it shows yellow images of clothes as shown in figure above. I just want to know how can I show colored images using colormap(). How to make colormap matrix(or array) in my code and map it to data matrix X. I don't know the procedure. I'll be grateful if you guide me in a proper way. Thanks jawad1492@gmail.com
I am following the code of Andrew NGs assignment 3 and 4
In order for the rgb2ind to be done consistently, you need to generate a colormap that you use for all of the images. For example you could pick one of the images and use
[first_ind_image, map] = rgb2ind(first_rgb_image);
and after that you would use
rgb2ind(other_image, map)
And then when you went to display, you would
colormap(map)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!