My final lab task is cropping parts from an image, inserting the cropped image to original back, rotating, and resizing it.
We have the image as a 2D array in a txt file, and Matlab converts the text files to images/image files to txts, so we can see our results.
With my code when I crop a square(image.extract_sub_image(0,0,100,100);), no problems but it inserts the cropped image to the opposite coordinates I don’t know why. Also when I crop a rectangle(image.extract_sub_image(0,0,100,50);) the program crashes. Also don’t know why 🙁
PS:
Read, write, get_dimensions functions are given by the prof.They are constant, and the header file is also given by the prof, **p2matr2D was his idea and I can’t change it.
My code : http://codepad.org/F0mfR7dN
goldhill.txt file : http://codepad.org/jfbeKLII
If I am not mistaken according to x,y coordinate system, x should be columns and y should be rows, and this is what I mean for opposite insertion : https://i.stack.imgur.com/UbfZf.png , green box is what I want, red box is what comes out …
The first 2 values in the text file determine the image dimensions, that’s how the prof arranged his Matlab script and C++ code.
I would be glad for your tips and comments to solve the problems.I know the code is long but I think I needed to paste everything in order to explain what I’m facing. The problem should be in CCTOR, =op, extract or insert functions.
It would seem to me that in some way, you’re inverting your columns with your rows. That would explain why when height is not the same as width, you get an exception and why it flips your picture when they are the same.
I didn’t look at your code, but I would imagine you’re simply using the row index for the column array and the column index for the row array in your 2-dimensional array. That’s the simplest cause.
Also, a tip for you: If you rewrite it as a 1-dimensional array of size height*width, you will get a drastic speed increase. Write a method which accepts an x and y coordinates and translates these coordinates into a single index for your 1-dimensional array and return the value so you don’t have to worry about details once you’ve made this method.