Question: I tried different ways to set a customized cookie name. But none is working in my configuration.

I have a Spring Boot application which is running in a standalone Tomcat.

I tried to set the cookie name in the `SpringBootApplication` class which is derived from `SpringBootServletInitializer`:

```
@Value("${session.cookie.name}")
private String sessionCookieName;

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    servletContext.getSessionCookieConfig().setName(sessionCookieName);
    super.onStartup(servletContext);
}

```

Also I tried to define a bean as `DefaultCookieSerializer`:

```
@Value("${session.cookie.name}")
private String sessionCookieName;

@Bean
public DefaultCookieSerializer defaultCookieSerializer(){
    DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
    defaultCookieSerializer.setCookieName(sessionCookieName);
    return defaultCookieSerializer;
}

```

But nothing is working so far, I always get the default `JSESSONID` instead of my configured `session.cookie.name`

Are there any other ways to customize the cookie name?

Answer: 
Assuming you have tried shape detectors, line detections, etc and not succeeded here is another way of solving this problem.

If this is a grayscale PNG image, you can use segmentation by color to achieve this.
I would approach it like so:

```
count = 0
For each pixel in the image:
    if color(pixel) == white /*255*/
        count++
        floodfill using this pixel as a seed pixel and target color as count

no_of_rectangles = count - 1 /* subtract 1 since the background will be colored too*/

```

This assumes the rectangles have continuous lines, else the floodfill will leak into other rectangles.
Filled or not should not make a difference if you find the outer contours (RETR\_EXTERNAL). Following code will give you number 3.
[![enter image description here](https://i.stack.imgur.com/WrZEH.png)](https://i.stack.imgur.com/WrZEH.png)

```
canvas = np.zeros(img.shape, np.uint8)
img2gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

ret,thresh = cv2.threshold(img2gray,128,255,cv2.THRESH_BINARY_INV)
im2,contours,hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

print(len(contours))

for cont in contours:
    cv2.drawContours(canvas, cont, -1, (0, 255, 0), 3)

cv2.imshow('contours',canvas)
cv2.waitKey(30000)
cv2.destroyAllWindows()

```

Notice if you use RETR\_TREE as the 2nd parameter in findContours(), you get all 6 contours, including the inner ones.
[![enter image description here](https://i.stack.imgur.com/CvcR1.png)](https://i.stack.imgur.com/CvcR1.png)

Obviously, this assumes that the image only contains rectangles and it doesn't distinguish different shapes.