Last Turn : Image Processing and Matrix values

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Last Turn : Image Processing and Matrix values

Julien563
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.JPG
I 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<R; %Condition 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 >=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)
Reply | Threaded
Open this post in threaded view
|

Re: Last Turn : Image Processing and Matrix values

nrjank
On Wed, Oct 26, 2016 at 3:07 PM, Julien563 <[hidden email]> wrote:
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?


Without seeing your code I'm guessing here:

for a color image, imread should produce a MxNx3 matrix that you named A. 

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.

To produce a transformed image B, your transformation function should also produce a MxNx3 matrix.  I'm not sure what you mean by merging A with B.  If B only holds the pixels that have been changed, then it is not a complete image.  Perhaps you need to copy non-empty elements of B back into A and then save A as your new image? 

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.

You should be able to create your output bmp from imwrite(B, 'outputimage.bmp').



_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Last Turn : Image Processing and Matrix values

Julien563
"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
Reply | Threaded
Open this post in threaded view
|

Re: Last Turn : Image Processing and Matrix values

nrjank

On Oct 26, 2016 5:10 PM, "Julien563" <[hidden email]> wrote:
>

> But, currently, the new question is : How to apply a total pixel
> transformation in a same time (RGB) for each pixels?

You simply need to tell it to work with the other values. You should read up on how Octave handles indexing and arrays with dimension greater than 2.

No special functions needed. A(1,2,3) is the 1st row, second column, 3rd 'page'. Using : is like saying 'all' for that dimension. So, A(1,2,:) is like saying the 1st row, second column on all three pages.

B(1,2,:) = A(2,1,:) will put all the 2,1 pixel values into the 1,2 location in B.

Indexing a n-dimensïonal array with less than n-dimensions can cause strange results if you font know how Octave handles that, which may explain why you were getting odd image output results. Also, only getting a black and white image makes sense if you were only messing with one color page.


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Last Turn : Image Processing and Matrix values

Julien563
This post was updated on .
Thx a lot,

 My last problem, is that for exemple : A(495;495,;) and B(495,495,;) are the same.

After transformation A(495,495,;) and B(495,495,:) should be different. Is it an error of affectation? Or just a problem with my equation? Because my equation are correct but no pixel changes position.

I did B=A

and after i apply changes in B from A. (Look my programm and you will understand what i mean)

Thx in advance

Julien
-------------------------------------------------------------------------------------------
A=imread('galaxy.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+15 %Distance de la masse par rapport à la Terre
z2= 2,75e+7%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=A
% 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
               
                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<R; %Condition 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 >=1) && (i <= nr) && (j >= 1) && (j <= nc))
                                A(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)