??? Error using ==> reshape To RESHAPE the number of elements must not change.
Error in ==> sym_rec_img_preprocess at 32 Ibox = reshape(Ibox,[4 ((sizer*sizec)/noimages)]);
Error in ==> sym_rec_main2 at 78 img = sym_rec_img_preprocess(I, sizer, sizec,noimages);
sizer = size3Dr; %32
sizec = size3Dc;
noimages = sizer/6;
I = I3Dtotal(:,:,i);
img = sym_rec_img_preprocess(I, size3Dr, size3Dc, noimages); % line 78
what am i doing wrong?

 采纳的回答

Matt Fig
Matt Fig 2011-4-6

0 个投票

Go into sym_rec_img_preprocess and put these right before line 32:
size(Ibox)
size(sizer)
size(sizec)
noimages
Then tell us what the output to the command window says.

21 个评论

??? Undefined function or variable 'Ibox'.
Error in ==> sym_rec_main2 at 32
size(Ibox)
This is the whole program so that you understand better
I3D1 = imread('IMG_0001.jpg');
I3D2 = imread('IMG_0002.jpg');
I3D3 = imread('IMG_0003.jpg');
I3D4 = imread('IMG_0004.jpg');
size3Dr = input('Enter number of training sets');
size3Dc = input('Enter number of different symbols');
sizer = size3Dr; %Assuming equal traning sets
sizec = size3Dc;
noimages = sizer/6;
%% Binarization of images of factory m/c symbols
Igray1 = rgb2gray(I3D1);
Ibw3D1 = im2bw(Igray1,graythresh(Igray1));
Igray2 = rgb2gray(I3D2);
Ibw3D2 = im2bw(Igray2,graythresh(Igray2));
Igray3 = rgb2gray(I3D3);
Ibw3D3 = im2bw(Igray3,graythresh(Igray3));
Igray4 = rgb2gray(I3D4);
Ibw3D4 = im2bw(Igray3,graythresh(Igray4));
I3Dtotal(:,:,1) = Ibw3D1;
I3Dtotal(:,:,2) = Ibw3D2;
I3Dtotal(:,:,3) = Ibw3D3;
I3Dtotal(:,:,4) = Ibw3D4;
%% Image Preprocessing
rfactor = 1;
crpval = 0;
for i = 1 : noimages
I = I3Dtotal(:,:,i);
img = sym_rec_img_preprocess(I, size3Dr, size3Dc, noimages);
for cnt = 1:((size3Dr*size3Dc)/noimages)
bw2 = img_crop(img{cnt}, rfactor, crpval);
charvec = img_resize(not(bw2));
out3D(:,cnt,i) = charvec;
end
end
Matt Fig
Matt Fig 2011-4-6
Which program? I asked you to put those lines in sym_rec_img_preprocess.
this is the original one. i did put those and the output was
??? Undefined function or variable 'Ibox'.
Error in ==> sym_rec_main2 at 32
size(Ibox)
Matt Fig
Matt Fig 2011-4-6
No, you put those lines in sym_rec_main2. Put them in this file:
sym_rec_img_preprocess
Type this at the command line:
edit sym_rec_img_preprocess
now put those lines I showed you right before line 32.
ok i did but it still gives me this error
??? Error using ==> reshape
To RESHAPE the number of elements must not change.
Error in ==> sym_rec_img_preprocess at 36
Ibox = reshape(Ibox,[4 ((sizer*sizec)/noimages)]);
Error in ==> sym_rec_main2 at 79
img = sym_rec_img_preprocess(I, size3Dr, size3Dc, noimages);
Matt Fig
Matt Fig 2011-4-6
O.k., but if you recall, I wanted you to tell the output of those 4 lines, not the error message! What is the output to the command window of those 4 lines?
aa ok sorry its just giving 24 10 24 10 24 10 , the values which i entered for training sets and different symbols respsectively
Matt Fig
Matt Fig 2011-4-6
Please format that so I can read it. Is it
24 10
24 10
24
10
or what? There should be four outputs.
excuse me i was seeing the command history instead. sorry im not so keen in matlab. so the results in the command window are like this
1 244
1 1
1 1
4
thanks for your help
Matt Fig
Matt Fig 2011-4-6
Great! No it is my turn to admit a mistake :-(. I gave you the wrong lines... it should be:
size(Ibox)
sizer
sizec
noimages
We'll eventually get to the bottom of this! Try those and tell what they say. Sorry about that....
it's ok, so now the results are these
ans =
1 244
sizer =
24
sizec =
10
noimages =
4
Matt Fig
Matt Fig 2011-4-6
Good. So we see the code is trying to reshape a size 1-by-244 (244 elements) array to be size 4-by-60 (240 elements).
So taking a guess, I am going to say that line should be:
Ibox = reshape(Ibox,[4 ((sizer*sizec)/noimages)+1]);
Give that a try (comment out the original and put that line in). It is only a guess, and may not work for other values. You will have to play around and see...
ok i did and it gives me this error
Error in ==> sym_rec_img_preprocess at
39
Ic = reshape(Ic,[2((sizer*sizec)/noimages)]);
currently it's like this
Ic = [Iprops.Centroid];
Ic = reshape(Ic,[2 ((sizer*sizec)/noimages)]);
Ic = Ic';
Ic(:,3) = (mean(Ic.^2,2)).^(1/2);
Ic(:,4) = 1:((sizer*sizec)/noimages);
Matt Fig
Matt Fig 2011-4-6
Ah, so now there is another error! So we made it past the first one, now on the the second error. Here is my recommendation at this point. Do what you did before, looking at the sizes of the input arguments to RESHAPE, and try to figure out what is wrong. I.e., now look at"
size(Ic)
Then figure out what is wrong here:
[2 ((sizer*sizec)/noimages)]
there might be a simple off by one error here too.
but it's still giving me error about the previous one
??? Error using ==> reshape
To RESHAPE the number of elements must
not change.
Error in ==> sym_rec_img_preprocess at
33
Ibox = reshape(Ibox,[4((sizer*sizec)/noimages)+1]);
Error in ==> sym_rec_main2 at 79
img = sym_rec_img_preprocess(I,size3Dr, size3Dc, noimages);
Sorry to disturb you but i can't seem to make this program work :(
Matt Fig
Matt Fig 2011-4-6
Now I am confused. First you said that you changed the code and got a new error on line 39. The old error was on line 32. So if the old error was still an error, how did the program get to line 39? The old error shouldn't be anymore if the numbers you told me are true. For example try this at the command line:
Ibox = rand(1,244); % A random array of the correct size.
sizer = 24;
sizec = 10;
noimages = 4;
reshape(Ibox,[4 ((sizer*sizec)/noimages)+1]); % No Error!!!
actually it's doing this:
if i leave Ic = reshape(Ic,[2 ((sizer*sizec)/noimages)]);
the error is
Error in ==> sym_rec_img_preprocess at 37
Ic = reshape(Ic,[2 ((sizer*sizec)/noimages)]);
when i did Ic = reshape(Ic,[2 ((sizer*sizec)/noimages)+1]);
it went back to line 32.
Matt Fig
Matt Fig 2011-4-6
Then I would guess that changing the Ic line allows the calling program (sym_rec_main2) to execute correctly for one value of input arguments, but the next call is what errors. This is what I eluded to earlier when I said that the fix might not cover all usages. I cannot offer more help without actually looking at all of the codes...
The best I can tell you is to look at your inputs each time and try to figure out the fix that covers all cases.
i sent you a personal msg...did you receive it?
Matt Fig
Matt Fig 2011-4-7
No, I didn't. Did you use the interface that comes up when you click my name? (Contact Matt Fig)

请先登录,再进行评论。

更多回答(2 个)

Laura Proctor
Laura Proctor 2011-4-6

0 个投票

In the code sym_rec_img_preprocess, you are trying to use RESHAPE to reshape the variable Ibox to a size that is incompatible with the original size of Ibox. Try putting in a breakpoint on line 32 of sym_rec_img_preprocess and determine the size of Ibox as well as the size of (sizer*sizec)/noimages, you will see that:
4*(sizer*sizec)/noimages ~= numel(Ibox)
stephanie borg
stephanie borg 2011-4-7

0 个投票

yes that 's what i did. is it possible if i send you the program? becaus I can't seem to do it write. When I eliminate all the errors it start again from the first one!

3 个评论

Matt Fig
Matt Fig 2011-4-7
I sent you a message with my email in it. Did you get it? I used the Contact Stephanie link on your Answers page. If you didn't get it, did you use a valid email when signing up for your MathWorks account?
hi this error: reshape To RESHAPE the number of elements must not change dont Appear in MATLAB VER 2018a
but this error I see in MATLAB2016b
Instead of asking in an 8 year old thread respond to your question.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Data Type Identification 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by