0

Already checked This SO Question , but my question is how to make changes appear to image after the calculation , and code will explain better , i have marked the line where is am confused:

% code written by Zulqurnain Jutt
img1 = imread('rotme.jpg');
img = img1;
[r,m] = size(img);
promt = 'Enter Angle to Rotate an image:=:';
x = input(promt);
% making antirotate matrix
coss = cos(x);
sinn = sin(x);
antirotate = floor( [coss -sinn 0;sinn coss 0; 0 0 1] );
for i=1:r
    for j=1:m
        %forming point matrix
        pointMat = [i-1;j-1;1];
        %multiplying both matrix
        mul = floor(antirotate*pointMat);
        % swapping points
        if mul(1)<0
          mul(1) =  abs(mul(1));
        end
        if mul(2)<0
            mul(2) =  abs(mul(2)); 
        end
        img( (mul(1)+1) , (mul(2)+1) )  = img(i,j); % Here Lies my problem
    end
end

imshow(img);

Problem 1: "Why the output in imshow after assigning the new pixel values giving me three different images as output red , green , blue. is there any way to fix it and get one image as output?"

Problem 2: "i am converting negative coordinates to positive is this okay?"

Note: it is homework question, and i am not hidding it. but is need help

Community
  • 1
  • 1
Zulqurnain Jutt
  • 1,083
  • 3
  • 15
  • 41
  • to glue back to RGB you need to use `cat` to glue back the 3 colors which I assume are `img(:,:,1)`,`img(:,:,2)` and `img(:,:,3)` your something like `img = cat(3, red, green, blue)` and how are you getting your negative coordinates? – GameOfThrows Apr 05 '16 at 13:56
  • in `mul` variable i am getting after multiplying matrices – Zulqurnain Jutt Apr 05 '16 at 14:30
  • 1
    oh that's just the rotation, yes, it is fine to convert those coordinates to positive. – GameOfThrows Apr 05 '16 at 14:35
  • as mentioned in problem in given line , i need to perform red , green and blue rotation separately and then glue them back ? – Zulqurnain Jutt Apr 05 '16 at 14:44
  • you can rotate them separately and glue them back or rotate them together it makes no difference - whichever is easier for you. – GameOfThrows Apr 05 '16 at 14:45
  • but as you can see , it is not working in my case , where i am trying to rotate image with supposition of 2d matrix ,and not dealing with 3rd index , but it is giving strange output , your suggestion is wrong i think. – Zulqurnain Jutt Apr 05 '16 at 14:51
  • `[r,m] = size(img);` If this is an RGB image, `m` is going to be `3x` the number of columns. I'm not sure if that's your problem, but it's really hard to tell without sample input and output images. – beaker Apr 05 '16 at 15:07
  • If you are not using the 3rd dimension, all that change is the way you index your matrix, but it does change how your final img should be concatenated, you would still using `img = cat(...)` you would still need to put in the indexes for red green and blue, your final img would still need to be 3D for imshow to work properly. – GameOfThrows Apr 05 '16 at 15:37

0 Answers0