1
$\begingroup$

I often try to crop images by selecting a few points manually with the interactive tools and copy-paste them in ImageTrim[theImage,ThePoints].

It works fine on small images and often doesn't work on large images. Here is a example that should be reproductible (Mathematica 12.1, Windows 7).

Let's say I want to crop a little bit this image :

TheImage = ExampleData[{"TestImage", "Apples"}]  

I select two points on the diagonal, very near the corners :

enter image description here

One sees on the animation that the points are at coordinates {11,15}, and {641,425}. I copy-paste them in ImageTrim :

ImageTrim[TheImage, {{11, 15}, {641, 425}}]  

result :

enter image description here

These are only the three apples at the bottom-right of the original image !

The question

Where does the coordinates system used by GetCoordinates comes from ?

$\endgroup$
5
  • $\begingroup$ @LouisB I have also unsuccessfully tried "Get Indices". I will try once again. But first note that the "Get Indices" obtained by the attached cell under the image doesn't give the same values then de "Get Indices" obtained by the contextuel menu. This is probably a bug. $\endgroup$
    – andre314
    Commented Dec 2, 2020 at 23:08
  • $\begingroup$ @LouisB I think you are refering to the"Get Indice" from the attached cell under the image. So far I remember there are also some problems. First I'm surpised that your image is not inverted (Top<-> Bottom inversion). But, as said, I will investigate this further (only tomorrow). $\endgroup$
    – andre314
    Commented Dec 2, 2020 at 23:12
  • $\begingroup$ My deleted comment regarding the indices was wrong. In MMA 11.3 for Windows I get the expected results using both the Get Coordinates flyout menu selection and the Coordinate Tool dialog shown in your animation. I then pasted the coordinates from MMA 11.3 into ImageTrim in MMA 12.1.0 for Linux and got the same correct result. But, when I use the coordinates obtained in MMA 12.1.0 for Linux, the results are wrong, as you report. The coordinates I used were from both the Get Coordinates flyout menu selection and from the Coordinates Tool shown in your animation. $\endgroup$
    – LouisB
    Commented Dec 3, 2020 at 10:49
  • $\begingroup$ The coordinate system used by the Get Coordinates tool is in points, not pixels. The indices are pixel coordinates, top-down. ImageTrim appears to want them as bottom-up, so a transform would appear to be necessary. $\endgroup$
    – ihojnicki
    Commented Dec 3, 2020 at 14:07
  • $\begingroup$ @ihojnicki I confirm that in this case a transform is necessary on pixel coordinates. I add that this transfom use ImageDimension[TheImage][[2]]. It is not convenient for everyday life (!). $\endgroup$
    – andre314
    Commented Dec 3, 2020 at 14:17

1 Answer 1

0
$\begingroup$

I have finally understood the origin of the coordinates system used by GetCoordinates.

It turns out that the image of apples has a Option called "ImageResolution" :

TheImage = ExampleData[{"TestImage", "Apples"}];
Options[TheImage] 

{ColorSpace -> "RGB", ImageResolution -> {300, 300}, Interleaving -> True}

(This option follows the image whatever copy/paste you do with the image. )

On the other hand, the size of the image in pixels is {2700,1800} :

ImageDimensions[TheImage]

{2700, 1800}

The coordinate system used by GetCoordinate is :

72/300 {2700,1800}

One reconize the 300,2700 and 1800. Regarding the 72, it is the standard resolution 72 dots/Inch.

$\endgroup$
2
  • $\begingroup$ Curiously one can't modify the option ImageResolution of the Image. My workaround is to use Image[ImageData[ theImage ]]. $\endgroup$
    – andre314
    Commented Jul 13, 2022 at 19:25
  • $\begingroup$ The following should work: img2 = Image[theImage, ImageResolution -> newValue] $\endgroup$
    – ihojnicki
    Commented Jul 13, 2022 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.