Sunday, 29 November 2020

How to Concatenate 5 Images Out Of Multiple Images In a Folder

I have a folder which has multiple images lets say images names are----

AB_1.jpg, AB_2.jpg, AB_3.jpg, AB_4.jpg, AB_5.jpg, AB_6.jpg, AB_7.jpg, AB_8.jpg, BC_1.jpg, BC_2.jpg, BC_3.jpg, CA_1.jpg, CA_2.jpg

Here my objective is to concatenate all the images till _5 or less than _5 as one image....

So basically what I am saying is that--- AB_1.jpg, AB_2.jpg, AB_3.jpg, AB_4.jpg, AB_5.jpg

will get concatenated vertically and file name lets say will be AB_Concat.jpg

_6,_7,_8 are skipped because we want to concatenate only images till _5 as one....

Similarly,, BC_1.jpg, BC_2.jpg, BC_3.jpg

will get concatenated vertically and file name lets say will be BC_Concat.jpg as you can see here BC_3 is last one which is less than _5 so all will be concatenated vertically.....

So if anyone have any idea on how to achieve the same please help....

This question is not similar to the once where two images are concatenated since here we are concatenating images on the basis of value after underscore in a image....

This is something which I tried--- '''python

import cv2

import shutil

import numpy as np

import os

from PIL import Image

path = r"D:\split"

out = r"D:\concat_test"

os.makedirs(out,exist_ok=True)

imag_name =[]

imag_name1 = []

for img in os.listdir(path):

folder  = img.rsplit("_",1)[0]  

imag_name1.append((folder,img))

images = cv2.imread(os.path.join(path,img),0)

imag_name.append((folder,images))

to create a folder for multiple images contain same name

for image,name in zip(imag_name,imag_name1):

if image[0] == name[0]:

    folder_n = os.path.join(out,name[0])

    final_fldr = os.path.join(folder_n,name[1])

    os.makedirs(folder_n,exist_ok=True)

    cv2.imwrite(final_fldr,image[1])

to concatinate the images

for root,dirs,files in os.walk(out):

np_images = [cv2.imread(os.path.join(root,file),0) for file in files]

np_name = list(set([file.rsplit("_",1)[0] for file in files]))


if len(np_images) != 0:

    print(np_name)

    concat = cv2.vconcat(np_images)

    concatinated_images = os.path.join(out,"concatinated_images")

    os.makedirs(concatinated_images,exist_ok=True)

    cv2.imwrite(os.path.join(concatinated_images,*np_name)+".tif",concat)

#to remove the unwanted folder

for remove_folder in os.listdir(out):

if remove_folder != "concatinated_images":

    folders_to_remove = os.path.join(out,remove_folder)

    shutil.rmtree(folders_to_remove)

'''



from How to Concatenate 5 Images Out Of Multiple Images In a Folder

How to add a horizontal scroll indicator for Android TabLayout

I am looking to add a horizontal scroll view for an Android TabLayout.

The TabLayout has multiple tabs in it and is scrollable. Due to multiple tabs on it, some of them are not visible at the first glance. The users have to scroll to get to the tabs on the far right(which are usually hidden) and so those tabs are not getting user's attention.

The thought is to have a horizontal scroll indicator or an arrow indicating that there are more tabs to the right so the users can scroll to find/use them.

The design idea is to have a scrollIndicator and not have a tabIndicator. I found the following image from Google which is closer to the idea. enter image description here

Thanks in advance,



from How to add a horizontal scroll indicator for Android TabLayout

Classify if point is within specified area using threshold - python

The aim of this question is to obtain some advice. I've got a df that contains xy points. I want to remove these points if they are located within a polygon. This is exhibited as area below. The points will come and go from this area, so I only want to remove when they are definitively placed within there.

The central dilemma is I don't want to pass a strict rule here. Because the points are fluid, I'm hoping to incorporate flexibility. For instance, some points may pass through this area temporarily and shouldn't be removed. While other points are located within the area long enough that they should be removed.

The obvious approach is to pass some method of threshold here. Using df1 below, A is located within the area for 3 frames, while B is located within the area for 7 frames. If I pass a threshold of >5 frames, B should be removed for all frames within this area, while A shouldn't be impacted.

The issue is, it has to be consecutive frames. The points will come and go, so I only want to remove after 5 consecutive frames.

Are there any other approaches I should consider?

import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import random

# general dataframe
df = pd.DataFrame(np.random.randint(-25,125,size=(500, 2)), columns=list('XY'))
labels = df['X'].apply(lambda x: random.choice(['A', 'B']) ) 
df['Label'] = labels
df['Time'] = range(1, len(df) + 1)

# edge cases
df1 = pd.DataFrame({
    'X' : [20,10,0,-5,-5,-5,0,10,20,30,20,10,0,-5,-5,-5,-5,-5,-5,-5],  
    'Y' : [50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50],                  
    'Label' : ['A','A','A','A','A','A','A','A','A','A','B','B','B','B','B','B','B','B','B','B'], 
    'Time' : [501,502,503,504,505,506,507,508,509,510,501,502,503,504,505,506,507,508,509,510],                         
    })

fig, ax = plt.subplots()
ax.set_xlim(-50, 150)
ax.set_ylim(-50, 150)

# designated area
x = ([1.5,-0.5,-1.25,-0.5,1.5,-11,-11,1.5]) 
y = ([75,62.5,50,37.5,25,25,75,75])

line = plt.plot(x,y)
Oval_patch = mpl.patches.Ellipse((50,50), 100, 150, color = 'k', fill = False)
ax.add_patch(Oval_patch)

pts = df[['X','Y']]
mask = line[0].get_path().contains_points(pts)
df = df[~mask]

A_X = np.array(df1.groupby(['Time'])['X'].apply(list))
A_Y = np.array(df1.groupby(['Time'])['Y'].apply(list))

ax.scatter(A_X[0], A_Y[0], c = 'purple', alpha = 0.2)


from Classify if point is within specified area using threshold - python