Open main menu

CDOT Wiki β

Changes

Savy Cat

995 bytes added, 19:14, 25 March 2018
Rotate90
img_tiny90(2, 0, 0, 2)
For any location at x & y, with width of image, height of image, and z (number of colour channels):
<nowiki>
The first portion of the index equation should look familiar (x + y * w) for indexing a square 2D matrix. Adding the result of (w * h * z) enables this to work for a rectangular matrix of z (3) dimensions.
 
==== The Rotate Operation ====
My rotate operation is simply an assignment operator. We initialize values of the rotated image one pixel at a time from the value stored in the source image. We calculate the new location based on the current location in the source image, using idx90. If we were rotating by any specified angle instead, it would require multiplying indices by a rotation matrix, then rounding values to integers. Since this is a triply nested operation, I suspect very small images will be OK, but Large_Shay.jpg (3264px x 2448px x 3) will require 23,970,816 operations! This should also be an ideal candidate for a parallel solution, as each pixel value assignment does not rely on completion of any prior operation.
 
<nowiki>
for (int i = 0; i < src.spectrum(); i++) {
for (int j = 0; j < src.height(); j++) {
for (int k = 0; k < src.width(); k++)
dst[idx90(k, j, src.width(), src.height(), i)] = src[idx(k, j, src.width(), src.height(), i)];
}</nowiki>
}
93
edits