I have a square image of 1000 x 1000 pixels, and I want to generate a collection of points inside the image. Knowing that the image is a square, I thought of simply generating points in the domain {0,1000}, then using Show[]
to observe the points (plus other computations later on, which is why I need this first). But when I use Show[]
the image appears smaller, strangely always in the {0,750} range. Strangely enough (to me at least) when I load my image directly from here (imgur.com), there's no problem. Only when I load the image from my local disk, the image shrinks. Why would that make a difference? Any help appreciated, thanks! (I'm using MMA 12.1 on Windows 10).
nPts = 1000;
mySquaredImage = Import["https://i.sstatic.net/owGLA.jpg"];
myImageDimensions = ImageDimensions[mySquaredImage];
myPoints = RandomReal[{0, myImageDimensions[[2]]}, {nPts, 2}];
Show[ListPlot[myPoints, PlotStyle -> Black],
SetAlphaChannel[mySquaredImage, 0.2]]
Exactly the same code, loading image from local disk, I get:
Thanks!
Information[localImage, "ImageResolution"]
it would return something like 120 or 192. The one you download will returnAutomatic
, which means 72. When it returns Automatic or 72, pixels and points are identical. Which is why your example happens to work on the web image. You need to convert coordinate systems for this to consistently work. $\endgroup$