<p>In your case, I don't think a pre-processing is necessary. You may find the <a href="https://en.wikipedia.org/wiki/Hough_transform" rel="nofollow noreferrer">Hough transform useful</a> in your case.</p>

<p>Since your image is big, it can be difficult to have a straight line due to the noise and blur.</p>

<p>This is what I got using a sobel contour detection with a smaller version of your image.</p>

<p>This is maybe a good start to use a line detection algorithm.</p>

<p><a href="https://i.sstatic.net/eAVQh.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eAVQh.jpg" alt="Input image after resizing and sobel contour detection"></a></p>

<p>A second solution would be to use color segmentation. If you assume that your screen would always have black border you can work something in the <a href="https://en.wikipedia.org/wiki/Lab_color_space" rel="nofollow noreferrer">L<em>A</em>b</a> or <a href="https://en.wikipedia.org/wiki/HSL_and_HSV" rel="nofollow noreferrer">HSV</a> color space.</p>

CC BY-SA 3.0
2017-07-31T07:57:01.183Z
2017-07-31T07:57:01.183Z
AlexM
<p>I think the result you've already shown is about as good as you're going to get. What you need isn't preprocessing of the input image, but to give your edge detector a good idea of what contour it's looking for. If you write your contour extractor to look specifically for quadrilaterals, it'll easily be able to filter where the fawn sticks out at the bottom left, and the stand at the bottom. Then it's just a question of finding the one that corresponds to the TV (probably the largest, but it depends on what other images you're running it on).</p>

CC BY-SA 3.0
2017-06-23T14:48:35.437Z
can you reference an implementation of a contour detector for which you can specify shape?  I was using find_contours (http://scikit-image.org/docs/dev/api/skimage.measure.html#find-contours) which apparently does no support that
dux2
CC BY-SA 3.0
2017-06-23T18:43:29.123Z
I can't think of an existing one; when I wrote the answer I was thinking you'd have to do it yourself. For an arbitrary shape that might be a lot of work but you're only looking for four lines.
Dan Hulme
CC BY-SA 3.0
2017-06-24T06:24:04.033Z
actually after using find_contours I am indeed looking for rectangle myself, but I thought that if I can make find_contours produce better contours, my final result will be more accurate and less prone to lighting conditions.
dux2
CC BY-SA 3.0
2017-06-23T09:35:41.487Z
2017-06-23T09:35:41.487Z
Dan Hulme
<p>I am trying to vectorize the contours (skewed rectangle) of the TV in the following original image.</p>

<p><a href="https://i.sstatic.net/pndvM.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pndvM.jpg" alt="oroginal"></a></p>

<p>My first step is applying threshold. Tried selection of threshold values based on what skimage has to offer, but non of them managed (for example) to separate correctly the little fawn to the left, or the TV stand from the TV border. For example this is the result using yen's method:</p>

<p><a href="https://i.sstatic.net/aEytA.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aEytA.jpg" alt="bw"></a></p>

<p>Can you suggest any preprocessing that may help before applying a threshold ?  </p>

<transformations><color><filtering>
Suggested image preprocessing before applying threshold
dux2
# Suggested image preprocessing before applying threshold

(Asked by: username_0 on 2017-06-23)

I am trying to vectorize the contours (skewed rectangle) of the TV in the following original image.

[![oroginal](https://i.sstatic.net/pndvM.jpg)](https://i.sstatic.net/pndvM.jpg)

My first step is applying threshold. Tried selection of threshold values based on what skimage has to offer, but non of them managed (for example) to separate correctly the little fawn to the left, or the TV stand from the TV border. For example this is the result using yen's method:

[![bw](https://i.sstatic.net/aEytA.jpg)](https://i.sstatic.net/aEytA.jpg)

Can you suggest any preprocessing that may help before applying a threshold ?

**Tags:** transformations, color, filtering


---

## 2 answers

### Answer by username_1 on 2017-07-31. Score: 1

In your case, I don't think a pre-processing is necessary. You may find the [Hough transform useful](https://en.wikipedia.org/wiki/Hough_transform) in your case.

Since your image is big, it can be difficult to have a straight line due to the noise and blur.

This is what I got using a sobel contour detection with a smaller version of your image.

This is maybe a good start to use a line detection algorithm.

[![Input image after resizing and sobel contour detection](https://i.sstatic.net/eAVQh.jpg)](https://i.sstatic.net/eAVQh.jpg)

A second solution would be to use color segmentation. If you assume that your screen would always have black border you can work something in the [L*A*b](https://en.wikipedia.org/wiki/Lab_color_space) or [HSV](https://en.wikipedia.org/wiki/HSL_and_HSV) color space.


---

### Answer by username_2 on 2017-06-23. Score: 0

I think the result you've already shown is about as good as you're going to get. What you need isn't preprocessing of the input image, but to give your edge detector a good idea of what contour it's looking for. If you write your contour extractor to look specifically for quadrilaterals, it'll easily be able to filter where the fawn sticks out at the bottom left, and the stand at the bottom. Then it's just a question of finding the one that corresponds to the TV (probably the largest, but it depends on what other images you're running it on).

> **Comments:**
> **username_0**: can you reference an implementation of a contour detector for which you can specify shape?  I was using find_contours (http://scikit-image.org/docs/dev/api/skimage.measure.html#find-contours) which apparently does no support that  
> **username_2**: I can't think of an existing one; when I wrote the answer I was thinking you'd have to do it yourself. For an arbitrary shape that might be a lot of work but you're only looking for four lines.  
> **username_0**: actually after using find_contours I am indeed looking for rectangle myself, but I thought that if I can make find_contours produce better contours, my final result will be more accurate and less prone to lighting conditions.  

---

