Displacing rows of pixels of an image to the bottom.
4 views (last 30 days)
Show older comments
I am trying to shift 1st to 1/12th of original rows to the bottom of the image.
I have been encountering an error that says "Unable to perform assignment because the size of the left side is 249-by-8964 and the size of the right side is 249-by-2988-by-3."
I tried applying reshape and squeeze method, but I do not even know how to apply them correctly.
Thank you in advance.
fileName = ('test.jpg');
original = imread(fileName);
[m,n] = size(original);
shifted = zeros([m,n]);
shifted(m*(11/12)+1:m,:,:) = original(1:m/12,:,:);
shifted(1:11*m/12,:,:) = original(m*11/12:m,:,:);
imshow(shifted);

0 Comments
Answers (1)
Walter Roberson
on 1 May 2019
Nearly all JPEG images are RGB images, even when they look gray. Certainly that image does not even look gray: it is clearly an RGB image. So you need to expect that the image array is 3 dimensional -- row, column, color-plane. However you ask
[m, n] = size(original);
shifted = zeros([m,n]);
What answer are you expecting from the size() call? You seem to be expecting number of rows and number of columns, and seem to be expecting that shifted would be created with that number of rows and columns. But then you assign into shifted(RANGE, :, :) which is a 3D assignment, not a 2D assignment, so you seem to be expecting that shifted is 3D not 2D. What is the mechanism by which you expect that zeros([m,n]) might give you a 3D array ? Are you expecting that when you do
[m, n] = size(original);
that size will send out the number of rows into m, and then send out all of the remaining dimensions as a vector in n, and then when you do the zeros([m,n]) that because you would be concatenating a scalar and vector that everything would work out okay to provide the 3D size information to the zeros() call?
You need to re-read the documentation on size().
You should also read the documentation on circshift()
Also think about:
A([4:20, 1:3], :, :) = A;
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!