Working with Matrices: Adding/Subtracting and Custom Operations

  • Thread starter Thread starter Jarfi
  • Start date Start date
  • Tags Tags
    Matrices
Click For Summary

Discussion Overview

The discussion revolves around performing matrix operations related to image processing, specifically adding and subtracting matrices that represent heatmaps and overlaying images of objects. Participants explore the mathematical and computational aspects of these operations, including transformations and pixel manipulation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a method for generating two matrices, M1 and M2, where M1 represents a heatmap and M2 represents an object overlay, and seeks a simple way to perform operations like M1 + M2 with transformations.
  • Another participant suggests that the operations described are more related to image processing than linear algebra and recommends using existing software libraries for such tasks.
  • A different participant reiterates the image processing perspective, emphasizing the need for pixel adjustments and overlays, and mentions specific libraries available in Java and Python.
  • One participant expresses a desire to avoid using libraries, arguing that the operations are basic matrix manipulations and should not require complex tools.
  • Another participant argues that the operations are not strictly linear algebra and suggests writing code or using libraries for efficiency, providing pseudocode for overlaying a house matrix onto a land matrix.
  • A later reply raises concerns about computational intensity when moving objects, suggesting that using pointers or block replacements might be more efficient for performance in graphics applications.
  • One participant notes that polygon meshes in computer graphics are ultimately converted to pixels and overlaid by the graphics card, indicating a connection between the discussed operations and graphical rendering techniques.

Areas of Agreement / Disagreement

Participants express differing views on whether the operations are primarily mathematical or image processing in nature. There is no consensus on the best approach to perform the desired matrix operations, with some advocating for coding solutions and others suggesting the use of libraries.

Contextual Notes

Participants mention potential computational inefficiencies and the complexity of operations as the size of the matrices increases, indicating that performance considerations are a significant aspect of the discussion.

Jarfi
Messages
384
Reaction score
12
TL;DR
How do I combine heatmaps, or images using simple matrix mathematics, in the simplest possible way?
Hello,

I am working with heatmaps and similar. And I want to be able to add/subtract them and a few other custom operations.

Here is a quick rundown:
1: Generate nxn (or nxm if possible) matrix, each element represents a heatmap color, or alternatively this could simply be defined as an image, let's call it M1

2: Generate another nxn matrix, but say with all elements transparents, except a certain area which represents a picture of an object, say a house. Alternatively, it can be an overlay of numbers, all 0 but in the area of interest, there are values 1-255, which can be a picture of something. Let's call it M2

3: I now want to do operations, such as M1 + M2 to get an overlay image, but not only this, I want to be able to control the change of basis or translate the position of the house in matrix M2 before adding it in M1, and do this multiple times, so I can add multiple houses onto the main image.

Main image = M1 + M2 * (location 1 transformation) + M2 * (location 2 transformation) so that I can add two houses to the matrix M1, on location 1 and location 2.

what is the most simple way to do this...? I assume the transformation can be defined in some way , so that all I need is matrix multiplication, so that most programming language can handle it?

But what if the house is size 50x50, and the main matrix is 500x500, but I put the house at location [0,250], so that half of the house would end up outside, but the other half still appears in the matrix, is this possible using some mathematical (non algorithmic) matrix transformation?
 
Technology news on Phys.org
These actions are more about image processing than about matrix operations.

Basically, it seems you want to adjust pixels, overlay pixels with other pixels, rescale one image to overlay on another image.

There are software libraries and tools to do that. Java has some libraries for as does Python. ImageMagick comes to mind for commands and Gimp for interactive tooling.
 
  • Like
Likes   Reactions: sysprog
jedishrfu said:
These actions are more about image processing than about matrix operations.

Basically, it seems you want to adjust pixels, overlay pixels with other pixels, rescale one image to overlay on another image.

There are software libraries and tools to do that. Java has some libraries for as does Python. ImageMagick comes to mind for commands and Gimp for interactive tooling.
It seems but it is not. I would like to do this without any clunky libraries, because it's very basic operations on nxn matrices, populated with simple numbers. It seems strange to me to have to revert to using libraries for this.

Again I am plotting heatmaps, not an rgb image
 
These actions aren't really linear algebra though.

Basically you need to write code or use libraries (better ie already debugged) that can do these manipulations.

In the case of the house placement:

Java:
// Java based psuedo code overlaying house array onto 
// the land array (realtors and witches beware a house may fall on you)
int land[][] = new int[100][100]; // land area
int house[][] = new int[10][10]; // house

// load land array
// load house array

// house position on land
int housex=25; //x coordinate of top right corner of house image
int housey=35; // y coordinate of top right corner of house image

// overlay house onto land
for(int i=0; i<house.length; i++) {
  for(int j=0; i<house[0].length; j++) {
    land[i+housex][j+housey]=house[i][j];
  }
}

show(land);
 
  • Like
Likes   Reactions: sysprog
jedishrfu said:
These actions aren't really linear algebra though.

Basically you need to write code or use libraries (better ie already debugged) that can do these manipulations.

In the case of the house placement:

Java:
// Java based psuedo code overlaying house array onto
// the land array (realtors and witches beware a house may fall on you)
int land[][] = new int[100][100]; // land area
int house[][] = new int[10][10]; // house

// load land array
// load house array

// house position on land
int housex=25; //x coordinate of top right corner of house image
int housey=35; // y coordinate of top right corner of house image

// overlay house onto land
for(int i=0; i<house.length; i++) {
  for(int j=0; i<house[0].length; j++) {
    land[i+housex][j+housey]=house[i][j];
  }
}

show(land);
This looks correct, and I have thought of doing this. But it also looks really computationally intensive. What If I want to make a moving house, for 30 fps, I need to do ixj=100 operations for each pixel, making 3.000 operations just for moving this single house. Or in case of a moving heamap (for example, a moving weather forecast showing the pressure degree, humidity or temperature) if I overlay more squares it might be 50x50x30 = 75.000 computations per second, the computation time increases exponantially with the size of the picture.

Perhaps it would be quicker to use pointers or something that switches out "blocks" of the matrix for another.
Pseudocode..
*land[(i+housex):(i+housex+5)][(j+housey):(j+housey+10)]=*house;

From my understanding, in computer graphics, they use graphical objects, where each one is basically a set of points connected together forming a polygon(mesh), then each object/matrix is transformed, rotated, translated etc and then added to the "main space" to make it move. There can be many objects, and together they form the image of whatever picture, video or graphics is being generated.
 
ultimately Though those polygon meshes are converted to pixels and overlaid into your image by the graphics card.
 

Similar threads

  • · Replies 48 ·
2
Replies
48
Views
7K
  • · Replies 11 ·
Replies
11
Views
7K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
1K