Difference between revisions of "KIAS primer"

From Cinemachines
Line 11: Line 11:
 
where h = screen height, w = screen width and sources[1] = input
 
where h = screen height, w = screen width and sources[1] = input
  
=== Mirror image ===
+
=== Flip image ===
 +
'''Vertical flip'''
 +
<nowiki>for( int y = 0; y < h; y++ ) {
 +
for( int x = 0; x < w; x++ ) {
 +
dist.at<Vec3b>(y,x)[0] = sources[1].at<Vec3b>(y,(w-x))[0];
 +
dist.at<Vec3b>(y,x)[1] = sources[1].at<Vec3b>(y,(w-x))[1];
 +
dist.at<Vec3b>(y,x)[2] = sources[1].at<Vec3b>(y,(w-x))[2];
 +
}
 +
}</nowiki>
 +
 
 +
'''Horisontal flip'''
 
  <nowiki>for( int y = 0; y < h; y++ ) {
 
  <nowiki>for( int y = 0; y < h; y++ ) {
 
for( int x = 0; x < w; x++ ) {
 
for( int x = 0; x < w; x++ ) {

Revision as of 11:22, 27 October 2019

Basic Image Processing

Displaying an Image

for( int y = 0; y < h; y++ ) {
	for( int x = 0; x < w; x++ ) {
		dist.at<Vec3b>(y,x)[0] = sources[1].at<Vec3b>(y,x)[0];
		dist.at<Vec3b>(y,x)[1] = sources[1].at<Vec3b>(y,x)[1];
		dist.at<Vec3b>(y,x)[2] = sources[1].at<Vec3b>(y,x)[2];
	}
}

where h = screen height, w = screen width and sources[1] = input

Flip image

Vertical flip

for( int y = 0; y < h; y++ ) {
	for( int x = 0; x < w; x++ ) {
		dist.at<Vec3b>(y,x)[0] = sources[1].at<Vec3b>(y,(w-x))[0];
		dist.at<Vec3b>(y,x)[1] = sources[1].at<Vec3b>(y,(w-x))[1];
		dist.at<Vec3b>(y,x)[2] = sources[1].at<Vec3b>(y,(w-x))[2];
	}
}

Horisontal flip

for( int y = 0; y < h; y++ ) {
	for( int x = 0; x < w; x++ ) {
		dist.at<Vec3b>(y,x)[0] = sources[1].at<Vec3b>(y,(w-x))[0];
		dist.at<Vec3b>(y,x)[1] = sources[1].at<Vec3b>(y,(w-x))[1];
		dist.at<Vec3b>(y,x)[2] = sources[1].at<Vec3b>(y,(w-x))[2];
	}
}