Backwards mapping?

Hello.

I am making a program to scale a greyscale picture. The code is working for me and gives me the picture I want, but it is asked to do backwards mapping. I have asked a lot of people who could not help me, even though they were studying programming, so I hope someone in here could help me. How do i implement a scalefunction that should implement backwards mapping? How would it look like?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include 
#include 
#include

using namespace std; 
using namespace cv;

void Scale(float Sx, float Sy, int imageWidth, int imageHeight) 
// The scaling function, taking four values from the main and creating the scaled image. 
{ 
Mat imageScaled(imageHeight * Sy, imageWidth * Sx, 0); 
Mat imageOriginal = imread("picture.jpg", CV_LOAD_IMAGE_COLOR); 
cvtColor(imageOriginal, imageOriginal, CV_BGR2GRAY);

for(int X = 0; X < imageWidth; X++){ 
for(int Y = 0; Y < imageHeight; Y++){ 
int OutputWidth = X * Sx; 
int OutputHeight = Y * Sy; 
imageScaled.at(OutputHeight, OutputWidth) = imageOriginal.at(Y, X); 
} 
} 
imshow("Original Input Image", imageOriginal); 
imshow("Scaled Image", imageScaled); 
}

int main() 
{ 
float Sx; 
float Sy; 
cout << "Forward Mapped Image Scaling" << endl << endl; 
cout << "Input file: "; 
Mat image = imread("picture.jpg", CV_LOAD_IMAGE_COLOR); 
if(! image.data || image.empty()){ 
cout << "..." << endl << endl << "Error!" << endl << "Could not open or find picture.jpg." << endl; 
} 
else{ 
cvtColor(image, image, CV_BGR2GRAY); 
cout << "picture.jpg" << endl; 
cout << "Image width: " << image.cols << endl; 
cout << "Image height: " << image.rows << endl << endl; 
cout << "Set the factors for the image's horizontal and vertical scaling." << endl; 
cout << "X axis (in %): "; 
cin >> Sx; 
cout << "Y axis (in %): "; 
cin >> Sy; 
Sx = Sx / 100; 
Sy = Sy / 100; 
cout << endl << "Applying the factors to the image size:" << endl; 
cout << "Scaled image width: " << image.cols * Sx << endl; 
cout << "Scaled image height: " << image.rows * Sy << endl;

Scale(Sx, Sy, image.cols, image.rows); 
waitKey(0); 
return 0; 
} 
}
What exactly do you mean by "backwards mapping"? Turning the grayscale to color? That can't be done. Turning the picture to grayscale throws away color information (hue) and saves only value.
This is what i got so far:

int newDimY = img.rows;
int newDimX = img.cols;

if (scaling the image up)

{

multiply original dimensions with the scaling factor when scaling up to obtain newDimY and newDimX

}

else if (scaling the image down)

{

Divide the original dimensions with the scaling factor when scaling down to obtain newDimY and newDimX

}
Mat outputimg(newDimY,newDimX,CV_8UC1,Scalar(0)); // here the new matrix is defined with the new dimensions

for ( int y = 0; y < outputimg.rows; ++y) //This runs thru the width of the image

{

for (int x = 0; x < outputimg.cols; ++x) //Runs thru the height of the image

{

Find the original position (xcalc, ycalc) of a pixel that is located at the position of (x, y) in the scaled image using the formula given in page 146

Check if this found position is within the dimensions of the original image, if yes:

outputimg.at<uchar>(y,x) = img.at<uchar>(ycalc, xcalc);//Here the new image is formed

}

}

Anyone who can help me out by filling in the code above?
Topic archived. No new replies allowed.