Skip to content

Commit

Permalink
Loop I
Browse files Browse the repository at this point in the history
- finally made the loop work
- Only removal of vertical seams possible at the moment - more coming soon
  • Loading branch information
Nico Steffens committed Nov 11, 2016
1 parent 83794ef commit 1b0723d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 57 deletions.
96 changes: 44 additions & 52 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,60 +66,62 @@ void MainWindow::on_pbComputeSeams_clicked()

/* .............. */

// Erstellen einer Arbeitskopie
cv::Mat workingCopy = originalImage.clone();
cv::Mat seamImage = originalImage.clone();
//originalImage.copyTo(workingCopy);
//originalImage.copyTo(seamImage);
//workingCopy = originalImage.clone();

// Generate Seams and push to fitting vector
/*NEW CODE*/

std::cout << "Processing..." << std::endl;

workingCopy = originalImage.clone();

// Loop for vertical seams
for (int i = 0; i < colsToRemove; i++){

cv::Mat tmpEnergyMap = calculateEnergy(workingCopy);
//cv::imshow("tmpEM", tmpEnergyMap);
std::cout << tmpEnergyMap << std::endl;
// Energymap berechnen
energyMap = calculateEnergy(workingCopy);

//cv::imshow("energyMap", energyMap);

// Seam berechnen

std::vector<cv::Point> tmpSeamV = findSeamV();

for(int i = 0; i < colsToRemove; i++){
//std::cout << tmpSeamV << std::endl;

/* First: Vertical Seams */
// löschen des Seams + stitching

// Calculate EnergyMap
workingCopy = removeSeamV(workingCopy, tmpSeamV);

cv::Mat tmpEnergyMap = calculateEnergy(workingCopy);
}

energyMap = tmpEnergyMap;
// Prepared horizontal seam removal
// for (int i = 0; i < rowsToRemove; i++){
// // Energymap berechnen
// energyMap = calculateEnergy(workingCopy);

std::vector<cv::Point> tmpSeamV = findSeamV();
// // Seam berechnen

std::cout << tmpSeamV << std::endl;
// std::vector<cv::Point> tmpSeamH = findSeamH();

// Calculate Seam
//std::vector<cv::Point> tmpSeamV = findSeamV();
// //std::cout << tmpSeamV << std::endl;

// // löschen des Seams + stitching

// workingCopy = removeSeamH(workingCopy, tmpSeamH);
// }

// Remove Seam from Image
//cv::Mat testMat = originalImage.clone();

// Not good in the loop.. change that later
cv::imshow("Removed img", workingCopy);

//seamImage = drawSeam(tmpSeamV, seamImage);

//cv::imshow("emap", energyMap);
//cv::imshow("wcopy", workingCopy);
//workingCopy = removeSeamV(workingCopy, tmpSeamV);

}
/*END NEW CODE*/

//cv::imshow("seamimage", seamImage);
// Debugging stuff
// std::cout << seamsV[0] << std::endl;
// std::cout << seamsV[1] << std::endl;
// std::cout << seamsH.size() << std::endl;

// for(int i = 0; i < rowsToRemove; i++){
// std::vector<cv::Point> seamH = findSeamH();
// std::vector<cv::Point> seamV = findSeamV();

// /* Second: Horizontal Seams */

Expand All @@ -143,8 +145,8 @@ void MainWindow::on_pbComputeSeams_clicked()
*/


/* Third: Display the seams for the user */
/*
cv::Mat seamImage = originalImage.clone();
// cv::imshow("Seam Image", originalImage);
Expand Down Expand Up @@ -211,8 +213,9 @@ cv::Mat MainWindow::removeSeamV(cv::Mat inputMat, std::vector<cv::Point> inputSe
}
}

cv::Mat cropped = inputMat(cv::Rect(0,0,inputMat.size().width-1,inputMat.size().height));

cv::Mat outputMat = inputMat(cv::Rect(0,0,inputMat.size().width-1,inputMat.size().height)).clone();
cv::Mat outputMat = cropped.clone();
//cv::imshow("Removed Seam V", outputMat);


Expand Down Expand Up @@ -385,7 +388,7 @@ std::vector<cv::Point> MainWindow::findSeamV(){

cv::Mat wayfindingMatrix = cv::Mat::zeros(energyMap.size(), energyMap.type());

// Fill the first column with initial contour strength values
// Fill the first row with initial contour strength values
for(int x = 0; x < wayfindingMatrix.size().width; x++){
int value = energyMap.at<cv::Vec3b>(cv::Point(x,0)).val[1];
wayfindingMatrix.at<cv::Vec3b>(cv::Point(x,0)) = cv::Vec3b(0,value,0);
Expand Down Expand Up @@ -515,31 +518,20 @@ cv::Mat MainWindow::calculateEnergy(cv::Mat inputImage){
// GrayScale EnergyMap
cv::Mat energyMap2 = cv::Mat::zeros(inputImage.size(), CV_32S);

//std::cout << energyMap2 << std::endl;


// Hier abfangen wenn Col/Row schon removed wurde
// workingCopy = originalImage.clone();

int imageWidth = inputImage.size().width;
int imageHeight = inputImage.size().height;

// Iterate over the whole image
for(int x = 0; x <= imageWidth; x++){
for(int y = 0; y <= imageHeight; y++){

for(int x = 0; x < imageWidth; x++){
for(int y = 0; y < imageHeight; y++){
cv::Point currentLocation = cv::Point(x,y);

int pixelEnergy = abs(sobelX(currentLocation, inputImage)) + abs(sobelY(currentLocation, inputImage));

int pixelEnergy = abs(sobelX(currentLocation)) + abs(sobelY(currentLocation));
// Set the value of the energypixel to the energymap in fancy green (BGR Notation in openCV)
energyMap2.at<int>(currentLocation) = pixelEnergy;

energyMap.at<cv::Vec3b>(currentLocation) = cv::Vec3b(0,pixelEnergy,0);
}
}
std::cout << energyMap2 << std::endl;
// Display the energyMap
return energyMap2;

return energyMap;
}

/*
Expand Down Expand Up @@ -585,7 +577,7 @@ int MainWindow::sobelY(cv::Point pixelLocation, cv::Mat inputImage){
cv::Vec3b lower_to_x;
cv::Vec3b upper_to_x;

int lower_border = inputImage.size().height-1;
int lower_border = workingCopy.size().height-1;

//Sonderbehandlung der Ränder
if(pixelLocation.y == 0){
Expand Down
8 changes: 4 additions & 4 deletions MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ private slots:
void on_pbOpenImage_clicked();
void on_pbComputeSeams_clicked();
void on_pbRemoveSeams_clicked();
cv::Mat calculateEnergy(cv::Mat inputImage);
int sobelX(cv::Point, cv::Mat inputImage);
int sobelY(cv::Point, cv::Mat inputImage);
cv::Mat calculateEnergy(cv::Mat);
int sobelX(cv::Point);
int sobelY(cv::Point);
std::vector<cv::Point> findSeamH();
std::vector<cv::Point> findSeamV();
cv::Mat removeSeamV(cv::Mat inputMat, std::vector<cv::Point> inputSeam);
Expand Down Expand Up @@ -73,8 +73,8 @@ private slots:
/* Originalbild */
cv::Mat originalImage;
/* Eventuel weitere Klassenattribute */
//cv::Mat workingCopy;
cv::Mat energyMap;
cv::Mat workingCopy;

std::vector<std::vector<cv::Point>> seamsV;
std::vector<std::vector<cv::Point>> seamsH;
Expand Down
2 changes: 1 addition & 1 deletion SeamCarving.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2016-11-10T11:47:04. -->
<!-- Written by QtCreator 3.0.1, 2016-11-10T13:28:02. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
Expand Down

0 comments on commit 1b0723d

Please sign in to comment.