How to subtract two image pixels - visual-c++

The overloaded operator-()must instantiate and return a PGMobject whose individual board member elements are equal to the absolute value of the differences in pixel values between the input and the calling objects. The PGM header information of the returned PGM object will be the same as the calling objec

Related

Integrating numba and Rtree.nearest()

I've been desperately looking to apply #numba.njit(parallel=True) to the rtree.nearest() function, but I get error statement of "no pyobject".
Since Rtree is a ctypes wrapper function, how can I apply the ctypes library and then use numba on Rtree.nearest?
Below is the pseudo-code:
Initialise variable coordinates_tree
Initialise variable MAX
Initialise variable 2d_coordinates_array
Initialise variable EMPTY euclidean_distance_array
Function start
Start for loop (MAX):
Change 2d_coordinates to tuple
Use rtree.nearest to find the nearest coordinate in tree (in form of object id)
Convert to list to retrieve the nearest coordinate
Convert to nearest coordinate numpy array
Calculate Euclidean distance between 2d_coordinate and nearest_coordinate
Store the Euclidean distance in euclidean_distance_array
Return euclidean_distance_array_array
Below is the documentation I've been investigating: https://numba.readthedocs.io/en/stable/user/cfunc.html
Essentially, do I have to make sure the input and output are ctypes?

Sklearn Binning Process - It is possible to return a interval?

I'm trying to use KBinsDiscretizer from sklearn.preprocessing, but it returns integer values as 1,2,..,N (representing the interval). Is it possible to return a correct interval as (0.2, 0.5) or this is not implemented yet?
based on the docs: https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.KBinsDiscretizer.html:
Attributes: n_bins_ : int array, shape (n_features,):
Number of bins per feature. Bins whose width are too small (i.e., <= 1e-8) are removed with a warning. bin_edges_ : array of arrays,
shape (n_features, ):
The edges of each bin. Contain arrays of varying shapes (n_bins_, ) Ignored features will have empty arrays.
This would mean a no in your case. There is also another hint:
The inverse_transform function converts the binned data into the original feature space. Each value will be equal to the mean of the two bin edges.```

How to pass vtkPolyData into vtkDijkstraGraphGeodesicPath?

This is what I have currently:
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(path);
polydata->Modified();
vtkSmartPointer<vtkDijkstraGraphGeodesicPath> dijkstra =
vtkSmartPointer<vtkDijkstraGraphGeodesicPath>::New();
dijkstra->SetInputData(polydata);
dijkstra->SetStartVertex(0);
dijkstra->SetEndVertex(1);
dijkstra->Update();
However, everytime it executes Update(), it returns vector subscript out of range. How can I fix this?
From vtkDijkstraGraphGeodesicPath documentation:
Takes as input a polygonal mesh ...
...
Warning The input polydata must have only triangle cells.
My guess is that your poly-data does not meet the necessary preconditions and is not a proper triangle mesh but just a point-set.
At least a call of vtkPolyData::SetLines() is needed to specify connections between vertices.

Polymorphism in node.js

I have a 2D matrix with 0s and 1s - respectively representing Water and Land. It is used to generate an animated gif with Perlin noise (moving water and waves clashing on shores...).
However I wish to refactor my code and use polymorphism in the following manner:
For each element in my matrix, based on the value, I wish to create a new WaterTile or LandTile (which will represent a 30x30 set of pixels that are either a mixture of blue for water, and some combinations of green/yellow/blue for land).
WaterTile and LandTile will be inherited from BaseTile (this is an abstract class), having just 2 vars (x, y for coordinates) and a draw() method (this method for the BaseTile class does nothing, its just there if it has to be defined).
Child classes will be overriding the draw() method.
Map will be a 2D array that whose elements will be WaterTiles and LandTiles.
After that, in my main method, I will have this (pseudocode for simplicity, i is index of row, j is index of element in that row):
foreach (row in matrix) {
foreach (element in row) {
if (matrix[i][j] == 0) map[i][j] == new WaterTile();
else map[i][j] == new LandTile();
}
}
After this I will need to invoke more methods for the LandTiles, and then have a new foreach loop, simply having
map[i][j].draw();//invoking draw method based on type
I know this can be done in other ways, but i wish to avoid having if statements that check for the type and call the draw method based on the type, and also practice clean code and learn something new.
If someone can provide me a simple example, ive looked at some already but havent found what I want.
Put the different actions inside the if statement you already have.
Or, just call the draw method, and let each instance do what it is does with draw.
Or encapsulate the if inside a function and use that.

How to read output of SmileBASIC SPCHK?

I'm trying to get the XY coordinates of a moving sprite in SmileBASIC, and I can't figure it out. I have the single variable returned from SPCHK, but when I print it, I get a single number '4' constantly as the sprite moves. How do I get each bit?
From the documentation:
Return Values for SPCHK
|b00| XY-coordinates (1), #CHKXY
|b01| Z-coordinates (2), #CHKZ
|b02| UV-coordinates (4), #CHKUV
|b03| Definition number (8), #CHKI
|b04| Rotation (16), #CHKR
|b05| Magnification XY (32), #CHKS
|b06| Display color (64), #CHKC
|b07| Variable (128), #CHKV
For each bit, a target is assigned (If 0 is assigned for all bits, animation is being stopped)
SPCHK only tells you which properties are currently being animated, not their values.
To get the actual position, you can use SPOFS id OUT x,y
Example:
SPSET 0,17
SPANIM 0,"XY",-10,100,100
WAIT 5
SPOFS 0 OUT X,Y
?X,Y 'should be 50,50

Resources