Message Boards Message Boards

Which coordinates are Y and X using ImageData?

Posted 4 years ago

Hi, I have used ImageData to extract the array of image. However, I require to determine the X and Y coordinates separately. I have used image partition and flatten, but its resulting 3D plot does not correspond to the original one. I have attached the .nb file. I will be grateful if you could help me to determine the X and Y coordinates respectively. Thanks

POSTED BY: Manoj Imrith
2 Replies
Posted 4 years ago

First your image is added:
img = enter image description here

Looking at the Dimensions you can see it has 3 color channels:

ImageData[img] // Dimensions

Therefore it is converted to Grayscale.

img2 = ColorConvert[img, "Grayscale"]

The graylevel coding is also inverted to match the use of Arrayplot, the array data are retrieved using ImageData

idata = ImageData[ColorNegate[img2]];

dims = idata // Dimensions

ArrayPlot[idata]

Now the array data is reorganized to fit ListPlot3D. First a matrix is created that holds the 2D indices plus a placeholder for the GrayLevel

lst = Outer[{#1, #2, 0} &, Range[First[dims]], Range[Last[dims]]];

Next the GrayLevel data are reconfigured to macth this format in order to be able to add both together

lst2 = Map[{0, 0, #} &, idata, {2}];
lst3 = lst + lst2;

Finally the data is displayed using ListPlot3D

ListPlot3D[Flatten[lst3, 1]]

Using Image the data can be converted back into a image, and a colornegate is required

ColorNegate[Image[idata]]
POSTED BY: Michael Helmle

From the documentation of ImageData:

In 2D, the array generated by ImageData[image] is arranged in the same way that the image is displayed, with the first row corresponding to the top row of pixels in the image.

Before feeding it to ListPlot3D you should rearrange the data, I guess.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract