matlab
@ikram002p Do you know much about pixel shifting?
nah sorry :'( as i don't have the program.
Okay no worries, thanks.
@jim_thompson5910
Should I prompt the user or not? I am not sure really how to set up the for loop without it.
I am suppose to use a nested for loop @jim_thompson5910
I got the image to shift without the loop
do I have the general idea? I got the prompts to work, however can't get the new image to display (simg)
why are you translating pixel by pixel? the function `imtranslate` shifts EVERY pixel of the image by the same amount http://www.mathworks.com/help/images/ref/imtranslate.html?searchHighlight=imtranslate
I'm guessing your teacher wants you to do every pixel?
oh I see now, the prof wants you to use nested loops
yes and I am suppose to shift pixel by pixel?
working on a small if else statement for original image.
let me think
clear, clc, close all; % clears all windows % loads image provided by instructor into matlab img = imread('dostoevsky.tif'); % x increases from 0 to 450, while % y decreses from 600 to 0 from bottom to top % displays image % asking use if wants to see original image original = input('Do you want to see original image? ', 's'); if (original == 'y' || original == 'Y') figure(1); imshow(img); axis on; elseif (original == 'n' || original == 'N'); fprintf('You said no. \n'); end % asking user to input x and y to transverse image x = input('Enter a X value, (must be a positive number): '); y = input('Enter a Y value, (must be a positive number): '); % for loops for k = 1:100 if (x > 0) % shifts image in x-positive direction simg(k) = imtranslate(img, [x, 0], 'outputview', 'full'); elseif (x < 0) fprintf('nothing will happen.'); end % second for loop for i = 1:100 if (y > 0) % shifts image y-positive direction simg(i) = imtranslate(img, [0, y], 'outputview', 'full'); elseif (y < 0) fprintf('nothing will happen.'); imshow(simg) end end end
ok trying something out
okay
hmm I'm getting weird results, one moment
okay. This is what I get Do you want to see original image? y Enter a X value, (must be a positive number): 100 Enter a Y value, (must be a positive number): 200 Subscripted assignment dimension mismatch.
I think I got it, but I have this weird blue/green portion
okay lol
what do you mean by blue/green portion?
ok what I did was hard code x = 50 and y = 100 just so I didn't have to type in x and y each time I tested this script
here's the m file and what the figure window looks like (2 attachments)
reading it now
% get the size of matrix img [m,n] = size(img); % set up matrix of numbering but 0s % this blank matrix is set to the size of matrix img simg = uint8(zeros(size(img))); % this matrix will later be filled by % the values found in matrix img
What does the top command do?
this command `[m,n] = size(img);` ?
yeah and don't worry about the color.
Does that command just get the size of the matrix?
simg = uint8(zeros(size(img))); and then this command sets a zero matrix up
`Does that command just get the size of the matrix?` yes the command "[m,n] = size(img);" gets the size of the matrix m rows n columns
and then what about simg = uint8(zeros(size(img)));
sets up a matrix of zeros it's the same size as matrix img
okay let me read on some more
What about this bit of code? for j = 1:1:m % 'for' loop designed to go through each column for k = 1:1:n % check to see if in bounds if( (j+y <= m) && (k+x <= n) ) % this line of code will assign the pixel value % of matrix img to matrix simg % with the shifts in mind simg(j+y,k+x) = img(j,k);
why did you go j = 1:1:m and k = 1:1:n
so j+y has to less or equal to m, m being the rows and k+x has to be less or equal to n because n is the columns
basically we can't go beyond the size of the matrix both in row and column
one question at a time please
so you figured out the question when you asked "why did you go j = 1:1:m and k = 1:1:n" ?
sorry I will ask you one question at a time Not really to the last question so you figured out the question when you asked "why did you go j = 1:1:m and k = 1:1:n" ?
j starts at 1, increments by 1, and keeps increment til it gets to m m = number of rows
k starts at 1, increments by 1, stops increasing til it equals n n = number of columns
j and k are indices to help go through the 2 'for' loops
okay
What about this part? % check to see if in bounds if( (j+y <= m) && (k+x <= n) ) % this line of code will assign the pixel value % of matrix img to matrix simg % with the shifts in mind simg(j+y,k+x) = img(j,k);
`if( (j+y <= m) && (k+x <= n) ) ` is to make sure that I didn't go past the boundaries I don't want to write in values into the simg matrix that shouldn't be there
`simg(j+y,k+x) = img(j,k);` is the part of code that does the actual shifting though for some reason, the blue part is there and I still don't know why
okay makes a lot of sense. I thought that was the case but just wanted to make sure my logic was correct.
so img is the original and simg is the new image with the shift constraints?
yes img = original simg = shifted
I guess img = image simg = shifted+image
okay that makes more sense.
uint8 ^^what does this command do
simg = uint8(zeros(size(img))); ^^^^ This
it converts the values to uint8 data types I think
uint = unsigned integer uint8 = 8 bit unsigned integer just a guess really
How did you know that we were not to exceed the mxn dimensions?
I knew the for loop needed a specific constraint but didn't know what it was suppose to be.
so the image shifts properly. Otherwise, the simg would be bigger than img
when you say 'bigger' you mean the size of the matrix?
IF I didn't do those bounds checks, then simg would be bigger let's say x = 50 y = 100 m = 200 n = 300 img would be a 200x300 matrix simg would be a 250x400 matrix that is if I didn't check to see if you went out of bounds or not
okay okay I see what you are saying.
Because if we didn't have the bounds there is a possibility the image would be 'hidden'. It would have been displayed somewhere not visible to the user?
|dw:1464663175284:dw|
Join our real-time social learning platform and learn together with your friends!