Location:Home > 最好的8个Java RESTful框架

最好的8个Java RESTful框架

up vote -3 down vote favorite

I have a bunch of image I would like to uniformise by removing black borders. Usually I use the Trim function of Imagemagick with the fuzz parameters but in the case the image have some watermark the result is not here.

Actually I'm making some tests with opencv and morphological transform to try to identify watermark and image and then select the bigger element but I'm really new with opencv and I struggle.

Watermark can be everywhere, from bottom left to upper right.

I would prefer a Python code but using some app like Imagemagick or similar is welcome.

Actually using opencv only I get this result:

import copy
import cv2

from matplotlib import pyplot as plt


IMG_IN = '/data/black_borders/island.jpg'


# keep a copy of original image
original = cv2.imread(IMG_IN)

# Read the image, convert it into grayscale, and make in binary image for threshold value of 1.
img = cv2.imread(IMG_IN,0)

# use binary threshold, all pixel that are beyond 3 are made white
_, thresh_original = cv2.threshold(img, 3, 255, cv2.THRESH_BINARY)

# Now find contours in it.
thresh = copy.copy(thresh_original)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

# get contours with highest height
lst_contours = []
for cnt in contours:
    ctr = cv2.boundingRect(cnt)
    lst_contours.append(ctr)
x,y,w,h = sorted(lst_contours, key=lambda coef: coef[3])[-1]


# draw contours
ctr = copy.copy(original)
cv2.rectangle(ctr, (x,y),(x+w,y+h),(0,255,0),2)


# display results with matplotlib

# original
original = original[:,:,::-1] # flip color for maptolib display
plt.subplot(221), plt.imshow(original)
plt.title('Original Image'), plt.xticks([]),plt.yticks([])

# Threshold
plt.subplot(222), plt.imshow(thresh_original, cmap='gray')
plt.title('threshold binary'), plt.xticks([]),plt.yticks([])

# selected area for future crop
ctr = ctr[:,:,::-1] # flip color for maptolib display
plt.subplot(223), plt.imshow(ctr)
plt.title('Selected area'), plt.xticks([]),plt.yticks([])

plt.show()

results:

python image opencv border share edited Feb 5 '14 at 18:06 asked Feb 5 '14 at 3:32 kollo 335 4 13 3   Could it be that the watermark is there for some reason? –  Hyperboreus Feb 5 '14 at 3:38 add a comment  | 

1 Answer 1

active oldest votes up vote 2 down vote accepted

To remove black borders:-

Follow this link(Perfect Answer I think) :-
Crop black edges with OpenCV

To remove black border by specifying region, follow this link
How i can do image CROP in OpenCV

Instead of cropping any part from image, you may take only ROI (Region of Interest). To do this, follow this link,
How to copy a image region using opencv in python?

To remove watermark:-

If watermark may appear anywhere in your image means, you cannot clear watermark fully. Just you may apply blurring effect on that image. It will blur your watermark.
Its link :
https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_imgproc/py_filtering/py_filtering.html


If watermark will exist only on the black border means, the above mentioned methods will solve your problem.

share answered Feb 5 '14 at 4:54 Thamizh 308 4 12      Thank you for your links, it helped me a bit to go further. But not enough to get rid of watermark. –  kollo Feb 5 '14 at 18:07 add a comment  | 

Your Answer

  draft saved draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name Email

Post as a guest

Name Email discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged python image opencv border or ask your own question.

Related
Your Answer
(Ctrl+Enter To Post)   
    Copyright © 2015-2017 163JAVA.COM All Rights Reserved.