# Last Turn : Image Processing and Matrix values

5 messages
Open this post in threaded view
|

## Last Turn : Image Processing and Matrix values

 This post was updated on . Hello evryone, I finally (almost) finished my project in IT, to finalize I would need one last time your advice on the matter. I insert a bmp format color image, 16-bit and trying to apply various image transformations. In fact I apply a transformation that will change the appearance of the image. I simply moves the pixels of my image to another location. It's that simple. All deflected pixels are placed in a matrix B. Knowing that the original image was decomposed into a matrix A by the following: A = imread ( 'test2.bmp'). So I apply the changes, everything works fine but my output image is completely disgusting. It is black and white and I can not see the transformations. Also knowing that the changes made have been inserted in the matrix B, it should not merge the matrix A with the matrix B? My result should resemble something of this style: http://www.epm6604b.be/lentille/images/imgfond/Lentille_gravitationnelle_ngc_4414.JPGI hope you see the style of transformation that I do. Hoping you can help me. Thank you very much The code : A=imread('test2.bmp'); % Les Constantes G= 6.67e-11 %Attention! Revoir les unités c=3.0e+8 M= 1,7e+38 %Masse de la masse déflectrice z1= 2,75e+22 %Distance de la masse par rapport à la Terre z2= 2,75e+22%Distance de la galaxie par rapport à la masse % Liste des Variables [nr,nc,channels]= size([A]) pixel_x1=round(nr/2)%Coordonnées de la masse pixel_y1=round(nc/2) pixel_x_metres=1e+16 pixel_y_metres=1e+16 pixel_x1_metres=(pixel_x_metres.*z1)./(z1+z2) pixel_y1_metres=(pixel_y_metres.*z1)./(z1+z2) R= (sqrt((pixel_x1_metres).^2+(pixel_y1_metres).^2)) %Rayon de la masse déflectrice (exemple de trou noir = 1 pixel) largeur = nr  %largeur de l'image en pixel longueur = nc %longueur de l'image en pixel L=(4.*G*M)./(c^2) B=[] % Lentille gravitationnelle for pixel_x_metres=(-ceil(nc./2).*(1e+16):(1e+16):floor(nc./2).*(1e+16));% Boucle OK         for pixel_y_metres=(-ceil(nr./2).*(1e+16):(1e+16):floor(nr./2).*(1e+16)); %Boucle OK                                 disp(pixel_x_metres)                 disp(pixel_y_metres)                                 pixel_x1_metres_boucle=(pixel_x_metres.*z1)./(z1+z2);                 pixel_y1_metres_boucle=(pixel_y_metres.*z1)./(z1+z2);                                 Ralpha = sqrt((pixel_x1_metres).^2+(pixel_y1_metres).^2); % A revoir                 if Ralpha=1) && (i <= nr) && (j >= 1) && (j <= nc))                                 B(i,j)= 0; % pixel noir OK                         endif                 else;                         nouveau_pixel_x_metres=pixel_x1_metres_boucle+z2.*((pixel_x1_metres_boucle./z1)-(L/Ralpha).*pixel_x1_metres/Ralpha) %OK                         nouveau_pixel_y_metres=pixel_y1_metres_boucle+z2.*((pixel_y1_metres_boucle./z1)-(L/Ralpha).*pixel_y1_metres/Ralpha) %OK                         j_nouveau=round((nouveau_pixel_x_metres)./(1e+16))+(floor(nr./2))+1 %OK                         i_nouveau=round((nouveau_pixel_y_metres)./(1e+16))+(floor(nc./2))+1 %OK                         j=round((pixel_x_metres)./(1e+16))+(floor(nr./2))+1 % OK                         i=round((pixel_y_metres)./(1e+16))+(floor(nc/2))+1 % OK                                         if ((i_nouveau >=1) && (i_nouveau <= nr) && (j_nouveau >= 1) && (j_nouveau <= nc))                                 if ((i >=1) && (i <= nr) && (j >= 1) && (j <= nc))                                         B(i_nouveau,j_nouveau) = A(i,j);                                 endif                         endif                 endif         endfor endfor imshow(B)
Open this post in threaded view
|

## Re: Last Turn : Image Processing and Matrix values

Open this post in threaded view
|

## Re: Last Turn : Image Processing and Matrix values

 "DON'T FORGET, 1 pixel has three values (one for R , G, and B colors). your MxN image is MxNx3, where the 3rd dimension is a different 'color'. If you want to move a pixel, you must move that value on all 3 of the color pages"  You're right, i thought that when i did after my transformation: B=[] B(i_nouveau,j_nouveau) = A(i,j) The 3 values (R,G,B) of A will be paste in B. Which command could be do this?  "Or, you could first copy A to B without any changes. Then apply your transformation to A, putting the output of the transformation into the correct location in B.  In that case B would be a complete image where you have just changed some pixels based on your transformation function." I used this kind of transformation in my programm, i tried to generate an empty matrix B, and after try to apply all pixel offshoring in matrix B and after it, i could maybe replace all pixels present in B in A to have a complete picture. But, currently, the new question is : How to apply a total pixel transformation in a same time (RGB) for each pixels? Thx in advance