Implement optimized C/C++ code using code optimization techniques
Consider an image to be represented as a two-dimensional matrix M, where Mi,j denotes the value of M[i][j] th pixel of M. Pixel values are triples of red, green, and blue (RGB) values. We will only consider square images. Let N denote the number of rows (or columns) of an image (NxN square image). Rows and columns are numbered, in C-style, from 0 to N-1. Given this representation, the rotate operation can be implemented as the combination of the following two matrix operations:
Transpose: For each (i,j) pair, Mi,j and Mj,i are interchanged.
Exchange rows: Row i is exchanged with row N-1-i 1)
First task is to rotate a given image counterclockwise in 90 degree. Use the model image given in the assignment folder for rotation. To do that, first transpose the image then exchange the rows. These operations are illustrated in the following figure. Notice how red pixel moved during matrix transpose and exchange rows matrix operations.

Please refer to code screenshots
code screenshot
![1 #include <iostream> #define N 4 4 using namespace std; 8 6 // function to transpose of A[][] 7- void transpose(int A[][N])](http://img.homeworklib.com/questions/b925e310-b5e9-11ea-8cd3-fbd747cebf3d.png?x-oss-process=image/resize,w_560)
![34 35int main() { 36 // matrix for testing functions int A[N][N] = { {10, 10, 10, 10}, {20, 20, 20, 20}, 30, 30, 30, 30}, {40](http://img.homeworklib.com/questions/b9a15000-b5e9-11ea-80b0-4d217e85e1a1.png?x-oss-process=image/resize,w_560)
Output

Code to copy
#include <iostream>
#define N 4
using namespace std;
// function to transpose of A[][]
void transpose(int A[][N]) {
int B[N][N]; // grid to store matrix
for (int i = 0; i < N; i++){
for (int j = 0; j < N;
j++){
B[i][j] =
A[j][i]; // getting transpose
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
A[i][j] = B[i][j]; // updating grid A
}
}
}
// function to exchange rows
void exchangeRows(int A[][N]){
for(int i = 0; i < N / 2; i++){
for(int j = 0; j < N; j++){
int p = N - 1 - i; // row to exchange with
// exchanging rows using swapping of elements
int temp = A[i][j];
A[i][j] = A[p][j];
A[p][j] = temp;
}
}
}
int main() {
// matrix for testing functions
int A[N][N] = {
{10, 10, 10, 10},
{20, 20, 20, 20},
{30, 30, 30, 30},
{40, 40, 40, 40}
};
transpose(A); // calling function to get
transpose of matrix
exchangeRows(A); // calling function to get exhange of
rows of matrix
cout<<"Matrix after rotation\n";
// displaying matrix after rotation
for (int i = 0; i < N; i++) {
for (int j = 0; j < N;
j++){
cout<<A[i][j]<<'
';
}
cout<<'\n';
}
return 0;
}
Implement optimized C/C++ code using code optimization techniques Consider an image to be represented as a...
**** In java matrix(2 dimensional array) size is fixed. so I have taken the new matrix (data2) in below code snippet. new matrix (data2) dimension is equal to transpose matrix's dimension of data. And I have sent each pixel value to the new matrix(data2). *** Pixel[][] data = theImage.getData(); Pixel[][] data2 = new Pixel[theImage.getWidth()][theImage.getHeight()]; for(int row=theImage.getHeight()-1; row>=0; row--){ for(int col=0; col<theImage.getWidth(); col++){ data2[col][(theImage.getHeight()-1)-row] = data[row][col]; } } theImage.setData(data2);...
convert the for loop into x86 assembly.. int[][] rotateMatrixBy90Degree(int[][] matrix, int n) { //We need to run the loop for only half the number of rows as it represents one quarter or quadrant for (int layer = 0; layer < n / 2; layer++) { //In every iteration, we reduce number of columns to be swapped by computing first and last column index. We are rotating counter clockwise. int first = layer; //start column pixel of current row...
How do I compile c++ code in terminal. Below i have some code to
apply Gaussian Filter on an image using OpenCV. I have tried
compling using the code
g++ Project2.cpp -o Project2 `pkg-config --cflags --libs opencv`
&& ./Project2
and it gives me a whole list of errors saying directory not
found.
---------------------------------------------------------------------------------------------------------
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image = imread("//u//oowens//First.jpg");
int rows=image.rows;
int cols=image.cols;
if (image.empty())...
I'm having trouble sorting this square matrix (a 2d array that has number of rows and same number of column n x n) using row-wise approach in C programming. Please help me program this in C to sort it using row-wise approach, here is the code: #include <stdio.h> #define MAX 100 int main() { int mat[MAX][MAX]; int i, j, m, n; int rowsum, columnsum, diagonalsum; int k; int magic = 0; int transpose[MAX][MAX]; printf("Enter the # of rows and columns...
Please code in C++.
link to continue the code is this below or you can make your
own code if you wish(fix any mistakes if you think there are any in
it):
cpp.sh/3qcekv
3. Submit a header file (project3.h), a definition file (project3.cpp), a main file (main.cpp), and a makefile to compile them together. Make sure to run the command make and produce an application file and include it with your submission. For this project, you are required to create...
from PIL import Image import random # NOTE: Feel free to add in any constant values you find useful to use BLACK = (0, 0, 0) WHITE = (255, 255, 255) # NOTE: Feel free to add in any helper functions to organize your code but # do NOT rename any existing functions (or else, autograder # won't be able to find them!!) # NOTE: The following function is already completed for you as an example # You can use...
use MATLAB to upload the following:
an image that you want to process (can be taken yourself or
downloaded from the internet)
a script that processes the image in TWO ways.
manipulates the colors
averages pixels together
Please make sure the script displays the images (like how I did
with the 40 and 80 pixel averaging) so I can easily compare them to
the original. Make sure to COMMENT your code as well.
Homework 13 Please upload the following: an...
I'm having trouble correctly sorting my 2d array/matrix. I need it so its row-wise sorted (meaning the values in the rows go from low to high). I tried to make the sort function but it just puts all the numbers from lowest to highest, up to down in column format. So please please help me fix it so it sorts correctly, I have bolded the code that needs to be fixed, everything else is fine. The code is below: #include...
Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...
Psuedocode works! DP is dynamic programming for this
algorithm
Problem 4.2. (Difficulty 3) Seam carving is a real-world application of DP for content- aware image resizing. The simplest way to reduce the size of an image is cropping and scaling, i.e. cutting out parts of the image and scaling down the size. However, cropping leaves visible crop lines of incontinuity while scaling reduces the details of the image. We would like to intelligently reducing the size while accounting for the...