Menu

#29 Get original image size after decoder hinting

v1.0_(example)
closed
nobody
None
5
2016-03-07
2016-03-04
No

Hello
I'm using decoder hinting while reading image to make resizing faster:
image.read(osize, inputUri)
then I apply crop
image.crop(cropGeom)
and
image.resize(osize)
The problem is that my input image is 2560x1600 and after reading with hinting it becomes 640x400 but the cropGeom that I pass is built against 2560x1600 and it failes with error: "Magick: geometry does not contain image (unable to crop image)".

How can I resolve my issue? By getting rid of decoder hint? Or maybe I could access original image size (2560x1600) i respectively modify cropGeom?
Thank you for your help.

Related

Support Requests: #29

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2016-03-04

    On Fri, 4 Mar 2016, Przemysław Sobala wrote:

    [support-requests:#29] Get original image size after decoder hinting

    Status: open Group: v1.0_(example) Created: Fri Mar 04, 2016 02:19 PM UTC by Przemysław Sobala Last Updated: Fri Mar 04,
    2016 02:19 PM UTC Owner: nobody

    Hello I'm using decoder hinting while reading image to make resizing faster: image.read(osize, inputUri) then I apply crop
    image.crop(cropGeom) and image.resize(osize) The problem is that my input image is 2560x1600 and after reading with hinting
    it becomes 640x400 but the cropGeom that I pass is built against 2560x1600 and it failes with error: "Magick: geometry does
    not contain image (unable to crop image)".

    How can I resolve my issue? By getting rid of decoder hint? Or maybe I could access original image size (2560x1600) i
    respectively modify cropGeom? Thank you for your help.

    Are you using the transform() method? This is the only method I can
    see which accepts both a size and a crop geometry. Otherwise, it
    seems that the problem is that you are using arguments which don't
    match the image which was actually read.

    After the image has been read using the Image read() method, you can
    now obtain its current size using the Image columns() and rows()
    methods. Build any necessary crop() arguments on the current image
    size. If the crop arguments are larger than both of the image
    dimensions, then you will obtain the error you reported.

    Bob

    --
    Bob Friesenhahn
    bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
    GraphicsMagick Maintainer, http://www.GraphicsMagick.org/

     

    Related

    Support Requests: #29

  • Przemysław Sobala

    I have a mechanism to detect faces in images. I'm using it to get coordinates and size of human faces in the image. Then I'm using those coordinates and size to cut them out of the image using a crop method and then resize the cut parts.
    I'm building crop() geometry based on original image dimensions (eg. 2560x1600) but after image.read(Geometry(400,300), inputUri) Magick++ API reports that input image has size 640x400 and my crop geometry is wrong, because it's based on orignial size 2560x1600.
    To sum up: my workflow is:
    1) detect face in input image of size 2560x1600
    2) read input image with hiting (400,300) - GM reports image.columns() x image.rows() = 640x480
    3) crop(225x225+295+487) - error! "geometry does not contain image (unable to crop image)" and i can agree with that
    4) resize(400,300)
    5) write

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2016-03-04

      On Fri, 4 Mar 2016, "Przemysław Sobala" wrote:

      I have a mechanism to detect faces in images. I'm using it to get coordinates and size of human faces in the image. Then I'm using
      those coordinates and size to cut them out of the image using a crop method and then resize the cut parts. I'm building crop()
      geometry based on original image dimensions (eg. 2560x1600) but after image.read(Geometry(400,300), inputUri) Magick++ API reports
      that input image has size 640x400 and my crop geometry is wrong, because it's based on orignial size 2560x1600. To sum up: my
      workflow is: 1) detect face in input image of size 2560x1600 2) read input image with hiting (400,300) - GM reports
      image.columns() x image.rows() = 640x480 3) crop(225x225+295+487) - error! "geometry does not contain image (unable to crop
      image)" and i can agree with that 4) resize(400,300) 5) write

      I am not completely understanding what you are looking for, but if you
      need the original dimensions of the JPEG input file, you should be
      able to obtain it from the Image baseColumns() and baseRows() methods
      immediately after reading the file. This should match your original
      size.

      Bob

      --
      Bob Friesenhahn
      bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
      GraphicsMagick Maintainer, http://www.GraphicsMagick.org/

       
  • Glenn Randers-Pehrson

    It's the opposite; they need the crop geometry in terms of the reduced image. In this case, the hint (400x300) results in a 640x400 image (original scaled by 1/4). So the cropping size and offsets need to also be divided by 4. The scale factor is predictable; it's the smallest 1/power-of-two scale that is large enough to contain the "hint" size.

    Either of the solutions mentioned in the original post should work (don't "hint", or record the original size and recompute the crop geometry.

     

    Last edit: Glenn Randers-Pehrson 2016-03-04
  • Przemysław Sobala

    Thanks to both of you. I scaled the cropping geometry, like Glenn said, based on image.base{Columns,Rows}(), like Bob suggested.
    That solved my problem.
    Have a nice day.

     
  • Glenn Randers-Pehrson

    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB