# Pixel-wise image manipulation

I downloaded an image from a website and imported it to Mathematica

img = Import["https://i.stack.imgur.com/fPZM7.jpg"];
Export["/path/to/file/fPZM7.txt",
Flatten[MapIndexed[Join[#2, #1] &, ImageData[img], {2}], 1], "Table"]


and create a .txt file with the pixel information

{{1, 1, 0.219608, 0.215686, 0.196078}, {1, 2, 0.219608, 0.215686,  0.196078},
{1, 3, 0.219608, 0.215686, 0.196078}, {1, 4, 0.219608,   0.215686, 0.196078},
{1, 5, 0.219608, 0.215686, 0.196078}, ..... ,
{944, 1396, 0.054902, 0.054902, 0.0470588}, {944, 1397, 0.00392157, 0.00784314, 0.},
{944, 1398, 0.00784314, 0.0117647, 0.}, {944, 1399, 0.0470588, 0.0509804, 0.027451},
{944, 1400, 0.0588235, 0.0627451, 0.0313725}}


which is a list of positions located at integer numbers followed by three real numbers defining the RGB color information of each point.

Then I import the .txt file

import = Import["/path/to/file/fPZM7.txt", "Data"]


and reconstruct the image using the basic code

Show[
Table[
Graphics[{
RGBColor[import[[i, 3]], import[[i, 4]], import[[i, 5]]],
Point[{import[[i, 1]], import[[i, 2]]}]
}],
{i, 1, Length[import]}
]
]


So far, the image is reconstructed (after a long long time) with no issues. However, if instead I want to manipulate the positions of the pixels, like

Show[Table[Graphics[{RGBColor[import[[i, 3]], import[[i, 4]], import[[i, 5]]], Point[{import[[i, 1]], import[[i, 2]]^2}]}], {i, 1, Length[import]}]]


or

Show[Table[Graphics[{RGBColor[import[[i, 3]], import[[i, 4]], import[[i, 5]]], Point[{import[[i, 1]], Sin[import[[i, 2]]]}]}], {i, 1, Length[import]}]]


I get a graphic in blank.

Does anybody know what happens there?

I would like to be able to manipulate the pixel positions and reconstruct another image out of the original one by changing the position of the pixels. Since all this process takes a lot of time: Does anybody know a more efficient way to plot the image back and the transformation?

• You know about Raster[], yes? – J. M. will be back soon Mar 14 at 16:38
• Let's leave aside how you are doing your calculations. What I don't understand is, what result you envision. You are modifying the positions of the pixels, e.g. by squaring one coordinate. This introduces gaps in the coordinates, i.e. instead of going {1,1},{1,2},{1,3}, they will give {1,1},{1,4},{1,9}. When you reconstruct your image, what values should we assign to the missing pixels in the new image, e.g. the ones between 1,4 and {1,9}? – MarcoB Mar 14 at 18:06
• If you want to move the pixels around, look at ImageTransformation and ImageForwardTransformation. If you want to change the values of the pixels themselves, ImageFilter and related commands would be your friend. – bill s Mar 14 at 19:27
• wow, thanks so much, ImageForwardTransformation solved my problem. – user115376 Mar 16 at 23:23