I am trying to convert a code in MatLab to OpenCV but I am stuck about the following lines as I don't know much programming, can someone here help me?
[n,m]=size(citra);
for x=1:n
k=m;
for y=1:m
citra_baru(k,x)=citra(x,y);
k=k-1;
end;
end;
and the full code is:
clc;
clear;
disp('Rotate Operation');
disp('--------------------');
disp('input file name with the extension');
image= input('input image file = ');
citra=imread(image);
[n,m]=size(citra);
for x=1:n
k=m;
for y=1:m
new_citra(k,x)=citra(x,y);
k=k-1;
end;
end;
subplot(1,2,1),imshow(citra),title('Citra Gray');
subplot(1,2,2),imshow(new_citra),title('Citra Rotate 90');
What I have tried:
i've tried to convert like this, but still error
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("D:\\Kuliah\\Pengolahan Citra Digital\\PCD\\images\\Fig3.35(a).jpg", CV_LOAD_IMAGE_UNCHANGED);
Mat img1(img.size(), img.type());
int n = img.size().width;
int m = img.size().height;
cout << n << " " << m;
for (int x = 1; x <= n; x++){
int k = m;
for (int y =1; y <= m; y++){
img1.at<uchar>(n, m) = img.at<uchar>(x, y);
(k,x) = (x,y);
}
k=k-1;
}
namedWindow("Original Image", CV_WINDOW_AUTOSIZE);
imshow("Original Image", img);
namedWindow("Cropped Image", CV_WINDOW_AUTOSIZE);
imshow("Cropped Image", img1);
waitKey(0);
return 0;
}