Can you use matrices to resize an image?

I am just curious if you could take a matrices to resize the x and y of an image? In maths there is "Row echelon form" or the "Reduced echelon form", which chops of a row. I don't know how you would do that to an image?, suppose you need to reduce it by a integer

Thanks :)

Tagged:

Answers

  • I don't know if this is what you need, but there is a getMatrix() and setMatrix() in Processing to change the current transformation matrix. You can resize images with transformation matrices.

  • hm, how would you do that? lets suppose you have an image of dimension ( 1500,2500), and you need to reduce it by factors of 5, or 10 so how would you set a matrix to reduce a row or a column of an image?

  • "reduce a row or column of an image"? Please elaborate.

  • edited January 2017

    @Ash160195 --

    suppose you have an image ... and you need to reduce it by factors of 5, or 10

    Are you trying to resize an image with independent width and height arguments? If so, use PImage.resize(w, h).

    You can also draw to a PGraphics buffer and then use .resize(w, h) to scale the buffer before rendering it to the screen with image(img).

    Finally, you can manipulate the scale of the transformation matrix stack directly using scale() -- which also accepts one, two, or three arguments. Use pushMatrix(); scale(x,y); image(img); popMatrix(); in order to set a scaling factor for a particular image and then restore the previous scaling for anything that you draw after.

    ...or, to set a specific matrix directly, follow the suggestion from @Lord_of_the_Galaxy and use setMatrix(). For more discussion (it is documented in the JavaDoc, not the public reference), see:

  • Ofcourse processing has a function for resize, but I was wondering if you could use a matrice, e.g we have a sharpen matrice, which iterates through every pixel. I was wondering if u could create a matrice which takes every pixel and reduces it? Ofcourse there is are easier methods to resize, but I wanted to devise a matrice that did resize every pixel? I don't think you can but it's worth asking

  • The set matrix is a good option, I'll look into that. Thanks!

  • e.g we have a sharpen matrice

    I'm trying to understand based on your example. First the "transformation matrix" is used for mapping, as with scale. Second, pixels is an array, and it is indeed operated on by things like resize using things like matrix operations. Third, if you want to directly manipulate pixels arrays using arbitrary matrix-like operations you may need of PShader / shaders.

    Depending on which you mean:

    1. Examine the Processing source code for PImage.resize to see how this is already done:

    2. Based on that example, consider the concept of a shader and look at the Processing Shader Tutorial:

Sign In or Register to comment.