Crop final stitched panorama image
I am using OpenCV to stitch images incrementally (Left to Right).
After the stitching process is complete I want to crop the result for final panorama.
Take this example panorama image:
How do I crop the image to remove the repeating part shown inside RED box on right ?
opencv image-processing image-stitching
add a comment |
I am using OpenCV to stitch images incrementally (Left to Right).
After the stitching process is complete I want to crop the result for final panorama.
Take this example panorama image:
How do I crop the image to remove the repeating part shown inside RED box on right ?
opencv image-processing image-stitching
1
Cropping would seem easy, just take the ROI that contains the non-repeating part. Perhaps you're looking for a method to detect that repetition, so you can do the cropping?
– Dan Mašek
Jan 1 at 19:19
1
yes, detect the repeating part and then crop so it forms a perfect cylindrical panorama image. Any idea how to achieve this?
– Manmohan Bishnoi
Jan 2 at 6:01
add a comment |
I am using OpenCV to stitch images incrementally (Left to Right).
After the stitching process is complete I want to crop the result for final panorama.
Take this example panorama image:
How do I crop the image to remove the repeating part shown inside RED box on right ?
opencv image-processing image-stitching
I am using OpenCV to stitch images incrementally (Left to Right).
After the stitching process is complete I want to crop the result for final panorama.
Take this example panorama image:
How do I crop the image to remove the repeating part shown inside RED box on right ?
opencv image-processing image-stitching
opencv image-processing image-stitching
asked Jan 1 at 13:15
Manmohan BishnoiManmohan Bishnoi
416828
416828
1
Cropping would seem easy, just take the ROI that contains the non-repeating part. Perhaps you're looking for a method to detect that repetition, so you can do the cropping?
– Dan Mašek
Jan 1 at 19:19
1
yes, detect the repeating part and then crop so it forms a perfect cylindrical panorama image. Any idea how to achieve this?
– Manmohan Bishnoi
Jan 2 at 6:01
add a comment |
1
Cropping would seem easy, just take the ROI that contains the non-repeating part. Perhaps you're looking for a method to detect that repetition, so you can do the cropping?
– Dan Mašek
Jan 1 at 19:19
1
yes, detect the repeating part and then crop so it forms a perfect cylindrical panorama image. Any idea how to achieve this?
– Manmohan Bishnoi
Jan 2 at 6:01
1
1
Cropping would seem easy, just take the ROI that contains the non-repeating part. Perhaps you're looking for a method to detect that repetition, so you can do the cropping?
– Dan Mašek
Jan 1 at 19:19
Cropping would seem easy, just take the ROI that contains the non-repeating part. Perhaps you're looking for a method to detect that repetition, so you can do the cropping?
– Dan Mašek
Jan 1 at 19:19
1
1
yes, detect the repeating part and then crop so it forms a perfect cylindrical panorama image. Any idea how to achieve this?
– Manmohan Bishnoi
Jan 2 at 6:01
yes, detect the repeating part and then crop so it forms a perfect cylindrical panorama image. Any idea how to achieve this?
– Manmohan Bishnoi
Jan 2 at 6:01
add a comment |
1 Answer
1
active
oldest
votes
I misunderstood your question. Regarding to your problem, take a 30-width-pixel window to the most left of the image as reference image, then slide over the x-axis of the image from left to right with a window of 30 pixels and then compare it with the reference image by the Mean Squared Error (MSE), the smaller the MSE is, the more similar the 2 images are. Look at the code for more details.
import matplotlib.pyplot as plt
import numpy as np
import cv2
img = cv2.imread('1.png')
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
h=img.shape[0]
w=img.shape[1]
window_length = 30 # bigger length means more accurate and slower computing.
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
# return the MSE, the lower the error, the more "similar"
# the two images are
return err
reference_img = img[:,0:window_length]
mse_values =
for i in range(window_length,w-window_length):
slide_image = img[:,i:i+window_length]
m = mse(reference_img,slide_image)
mse_values.append(m)
#find the min MSE. Its index is where the image starts repeating
min_mse = min(mse_values)
index = mse_values.index(min_mse)+window_length
print(min_mse)
print(index)
repetition = img[:,index:index+window_length]
# setup the figure
fig = plt.figure("compare")
plt.suptitle("MSE: %.2f"% (min_mse))
# show first image
ax = fig.add_subplot(1, 2, 1)
plt.imshow(reference_img, cmap = plt.cm.gray)
plt.axis("off")
# show the second image
ax = fig.add_subplot(1, 2, 2)
plt.imshow(repetition, cmap = plt.cm.gray)
plt.axis("off")
cropped_img = img[:,0:index]
cv2.imshow("img", img)
cv2.imshow("cropped_img", cropped_img)
# show the plot
plt.show()
cv2.waitKey()
cv2.destroyAllWindows()
The idea of comparing 2 images comes from this post: https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
Not a simple crop. I need to crop where the image starts repeating. That would include process to detect repeating pattern and then getting width on where to crop
– Manmohan Bishnoi
Jan 2 at 6:06
@ManmohanBishnoi Yes, I misunderstood your OP. I edited my answer.
– Ha Bom
Jan 2 at 9:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995738%2fcrop-final-stitched-panorama-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I misunderstood your question. Regarding to your problem, take a 30-width-pixel window to the most left of the image as reference image, then slide over the x-axis of the image from left to right with a window of 30 pixels and then compare it with the reference image by the Mean Squared Error (MSE), the smaller the MSE is, the more similar the 2 images are. Look at the code for more details.
import matplotlib.pyplot as plt
import numpy as np
import cv2
img = cv2.imread('1.png')
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
h=img.shape[0]
w=img.shape[1]
window_length = 30 # bigger length means more accurate and slower computing.
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
# return the MSE, the lower the error, the more "similar"
# the two images are
return err
reference_img = img[:,0:window_length]
mse_values =
for i in range(window_length,w-window_length):
slide_image = img[:,i:i+window_length]
m = mse(reference_img,slide_image)
mse_values.append(m)
#find the min MSE. Its index is where the image starts repeating
min_mse = min(mse_values)
index = mse_values.index(min_mse)+window_length
print(min_mse)
print(index)
repetition = img[:,index:index+window_length]
# setup the figure
fig = plt.figure("compare")
plt.suptitle("MSE: %.2f"% (min_mse))
# show first image
ax = fig.add_subplot(1, 2, 1)
plt.imshow(reference_img, cmap = plt.cm.gray)
plt.axis("off")
# show the second image
ax = fig.add_subplot(1, 2, 2)
plt.imshow(repetition, cmap = plt.cm.gray)
plt.axis("off")
cropped_img = img[:,0:index]
cv2.imshow("img", img)
cv2.imshow("cropped_img", cropped_img)
# show the plot
plt.show()
cv2.waitKey()
cv2.destroyAllWindows()
The idea of comparing 2 images comes from this post: https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
Not a simple crop. I need to crop where the image starts repeating. That would include process to detect repeating pattern and then getting width on where to crop
– Manmohan Bishnoi
Jan 2 at 6:06
@ManmohanBishnoi Yes, I misunderstood your OP. I edited my answer.
– Ha Bom
Jan 2 at 9:50
add a comment |
I misunderstood your question. Regarding to your problem, take a 30-width-pixel window to the most left of the image as reference image, then slide over the x-axis of the image from left to right with a window of 30 pixels and then compare it with the reference image by the Mean Squared Error (MSE), the smaller the MSE is, the more similar the 2 images are. Look at the code for more details.
import matplotlib.pyplot as plt
import numpy as np
import cv2
img = cv2.imread('1.png')
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
h=img.shape[0]
w=img.shape[1]
window_length = 30 # bigger length means more accurate and slower computing.
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
# return the MSE, the lower the error, the more "similar"
# the two images are
return err
reference_img = img[:,0:window_length]
mse_values =
for i in range(window_length,w-window_length):
slide_image = img[:,i:i+window_length]
m = mse(reference_img,slide_image)
mse_values.append(m)
#find the min MSE. Its index is where the image starts repeating
min_mse = min(mse_values)
index = mse_values.index(min_mse)+window_length
print(min_mse)
print(index)
repetition = img[:,index:index+window_length]
# setup the figure
fig = plt.figure("compare")
plt.suptitle("MSE: %.2f"% (min_mse))
# show first image
ax = fig.add_subplot(1, 2, 1)
plt.imshow(reference_img, cmap = plt.cm.gray)
plt.axis("off")
# show the second image
ax = fig.add_subplot(1, 2, 2)
plt.imshow(repetition, cmap = plt.cm.gray)
plt.axis("off")
cropped_img = img[:,0:index]
cv2.imshow("img", img)
cv2.imshow("cropped_img", cropped_img)
# show the plot
plt.show()
cv2.waitKey()
cv2.destroyAllWindows()
The idea of comparing 2 images comes from this post: https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
Not a simple crop. I need to crop where the image starts repeating. That would include process to detect repeating pattern and then getting width on where to crop
– Manmohan Bishnoi
Jan 2 at 6:06
@ManmohanBishnoi Yes, I misunderstood your OP. I edited my answer.
– Ha Bom
Jan 2 at 9:50
add a comment |
I misunderstood your question. Regarding to your problem, take a 30-width-pixel window to the most left of the image as reference image, then slide over the x-axis of the image from left to right with a window of 30 pixels and then compare it with the reference image by the Mean Squared Error (MSE), the smaller the MSE is, the more similar the 2 images are. Look at the code for more details.
import matplotlib.pyplot as plt
import numpy as np
import cv2
img = cv2.imread('1.png')
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
h=img.shape[0]
w=img.shape[1]
window_length = 30 # bigger length means more accurate and slower computing.
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
# return the MSE, the lower the error, the more "similar"
# the two images are
return err
reference_img = img[:,0:window_length]
mse_values =
for i in range(window_length,w-window_length):
slide_image = img[:,i:i+window_length]
m = mse(reference_img,slide_image)
mse_values.append(m)
#find the min MSE. Its index is where the image starts repeating
min_mse = min(mse_values)
index = mse_values.index(min_mse)+window_length
print(min_mse)
print(index)
repetition = img[:,index:index+window_length]
# setup the figure
fig = plt.figure("compare")
plt.suptitle("MSE: %.2f"% (min_mse))
# show first image
ax = fig.add_subplot(1, 2, 1)
plt.imshow(reference_img, cmap = plt.cm.gray)
plt.axis("off")
# show the second image
ax = fig.add_subplot(1, 2, 2)
plt.imshow(repetition, cmap = plt.cm.gray)
plt.axis("off")
cropped_img = img[:,0:index]
cv2.imshow("img", img)
cv2.imshow("cropped_img", cropped_img)
# show the plot
plt.show()
cv2.waitKey()
cv2.destroyAllWindows()
The idea of comparing 2 images comes from this post: https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
I misunderstood your question. Regarding to your problem, take a 30-width-pixel window to the most left of the image as reference image, then slide over the x-axis of the image from left to right with a window of 30 pixels and then compare it with the reference image by the Mean Squared Error (MSE), the smaller the MSE is, the more similar the 2 images are. Look at the code for more details.
import matplotlib.pyplot as plt
import numpy as np
import cv2
img = cv2.imread('1.png')
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
h=img.shape[0]
w=img.shape[1]
window_length = 30 # bigger length means more accurate and slower computing.
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
# return the MSE, the lower the error, the more "similar"
# the two images are
return err
reference_img = img[:,0:window_length]
mse_values =
for i in range(window_length,w-window_length):
slide_image = img[:,i:i+window_length]
m = mse(reference_img,slide_image)
mse_values.append(m)
#find the min MSE. Its index is where the image starts repeating
min_mse = min(mse_values)
index = mse_values.index(min_mse)+window_length
print(min_mse)
print(index)
repetition = img[:,index:index+window_length]
# setup the figure
fig = plt.figure("compare")
plt.suptitle("MSE: %.2f"% (min_mse))
# show first image
ax = fig.add_subplot(1, 2, 1)
plt.imshow(reference_img, cmap = plt.cm.gray)
plt.axis("off")
# show the second image
ax = fig.add_subplot(1, 2, 2)
plt.imshow(repetition, cmap = plt.cm.gray)
plt.axis("off")
cropped_img = img[:,0:index]
cv2.imshow("img", img)
cv2.imshow("cropped_img", cropped_img)
# show the plot
plt.show()
cv2.waitKey()
cv2.destroyAllWindows()
The idea of comparing 2 images comes from this post: https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
edited Jan 2 at 10:18
answered Jan 2 at 1:48
Ha BomHa Bom
1,3032519
1,3032519
Not a simple crop. I need to crop where the image starts repeating. That would include process to detect repeating pattern and then getting width on where to crop
– Manmohan Bishnoi
Jan 2 at 6:06
@ManmohanBishnoi Yes, I misunderstood your OP. I edited my answer.
– Ha Bom
Jan 2 at 9:50
add a comment |
Not a simple crop. I need to crop where the image starts repeating. That would include process to detect repeating pattern and then getting width on where to crop
– Manmohan Bishnoi
Jan 2 at 6:06
@ManmohanBishnoi Yes, I misunderstood your OP. I edited my answer.
– Ha Bom
Jan 2 at 9:50
Not a simple crop. I need to crop where the image starts repeating. That would include process to detect repeating pattern and then getting width on where to crop
– Manmohan Bishnoi
Jan 2 at 6:06
Not a simple crop. I need to crop where the image starts repeating. That would include process to detect repeating pattern and then getting width on where to crop
– Manmohan Bishnoi
Jan 2 at 6:06
@ManmohanBishnoi Yes, I misunderstood your OP. I edited my answer.
– Ha Bom
Jan 2 at 9:50
@ManmohanBishnoi Yes, I misunderstood your OP. I edited my answer.
– Ha Bom
Jan 2 at 9:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995738%2fcrop-final-stitched-panorama-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Cropping would seem easy, just take the ROI that contains the non-repeating part. Perhaps you're looking for a method to detect that repetition, so you can do the cropping?
– Dan Mašek
Jan 1 at 19:19
1
yes, detect the repeating part and then crop so it forms a perfect cylindrical panorama image. Any idea how to achieve this?
– Manmohan Bishnoi
Jan 2 at 6:01