Skip to main content
Archived

RasterResampler: preserve original cell size ratio

Related products:Transformers
  • February 20, 2016
  • 4 replies
  • 28 views
danilo_fme
  • danilo_fme
    danilo_fme

geosander

I recently needed to resample some RGB rasters to a different size (using RowsColumns), causing the aspect ratio to change. FME then changes the raster cell spacing, so that it's no longer [1,1] but [0.8,0.65] for instance. Seems more like scaling than resampling to me, but okay...
Now what if I want to output this raster to a format that only supports square cells? Depending on the size, FME resizes it again before writing, so I end up with the original raster or some weird compromise (e.g. [0.7,0.7]).

This is why I propose a "Force Square Cells/Preserve Cell Size Ratio" option for the RasterResampler (when resampling using the RowsColumns option).

By the way: I'm now using a SystemCaller with an IrfanView command line to achieve this. It works, but it feels a bit hacky.. ;)

This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • February 21, 2016

Hi @sander_s, can you point us at the exact IrfanView command line you're using? It would help us understand the definition of resampling -- we may be a bit off on ours. In our understanding, if you have a raster that is say 10 by 10 and you ask for a new raster to be made out of it that is instead 3 by 5, I can't see how we could do anything other than have non-square pixels at the end. By definition, we want the raster to still cover the same ground coordinates. So with different numbers of cells in different dimensions, they'd have to be non-square. But perhaps what you're looking for is more of clipping function? Where the size of the pixels would not change but if you wanted fewer of them you'd be getting an image that covered a smaller area?

Thanks for your input.


geosander
Forum|alt.badge.img+7
  • Author
  • February 21, 2016

Hi @daleatsafe, thanks for picking this up! I completely forgot that "forcing square cells" would inevitably mean that the raster extent also would change, sorry! The thing is: I don't care about that ;)

Let me explain what I'm doing here: I am converting 3D models into the Three.js format using my own workflow (the Three.js function in the JSONTemplater was a bit too limited). Most of the textures have a REPEAT_BOTH wrap setting, but a lot of texture images in (amateur made) 3D models do not have dimensions that are a power of 2 (2, 4, 16, 32 etc.). This is a limitation of WebGL. If the dimensions are not a power of 2, it will default to clamp-to-edge wrapping, which might lead to incorrect texture mapping.

So yes, in my case, I don't care about the raster extent, as my rasters are non-geographic. Resampling could then work as follows:

  1. After the user specified the rows and columns, the RasterResampler calculates how big the ground extent would become if we'd keep the same cell size
  2. Scale the input raster so it fits this new extent (leading to non-square cells)
  3. Create a new raster with the new extent but the original input cell size
  4. Lookup (interpolate) the proper values for each cell in the input raster and save them in the output raster

To deal with the extent problem, I would suggest that a "Force Square Cells" option only works for rasters that do not have a spatial reference. It wouldn't make sense otherwise.

Anyway.. this is probably another (too) specific feature request on my behalf ;)

PS: The IrfanView command line for the SystemCaller is

 

""<path_to_IrfanView.exe>" "<input_raster_file_path>" /resize=(<columns>,<rows>) /resample /convert="<output_raster_file_path"

fmelizard
Contributor
Forum|alt.badge.img+17
  • Contributor
  • February 22, 2016

Okay, I discussed with the team and they suggest:

 

 

The easiest way to do this is to use a RasterGeoreferencer after resampling and set the spacing to (1, 1) (the origin can also be set to (0, 0) to preserve our notion that it's an unreferenced raster, but I don't think it matters). Explicitly setting the spacing will prevent the raster from being resampled by writers that require square pixels.

Hope that makes sense, maybe give it a spin?


geosander
Forum|alt.badge.img+7
  • Author
  • February 22, 2016

Yes, that works!

 

However, it does produce a less good-looking image compared to IrfanView. But since it's stretched and gets rescaled and rendered by WebGL, it might look fine again in 3D. I'll do some comparisons and then decide what's the best approach.

 

Either way: thanks for your suggestion! :)

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings