0
$\begingroup$

I'm currently going through issues in terms of acquiring multiple images at once to convert them to a vector for calculating the cosine distance to get similarity between say an image from the directory compared to another. From looking around, I can't use tensors/arrays to calculate these distances, but please correct me if I'm wrong.

Here is an example of my code:

import numpy as np
import os
import cv2
import glob
from skimage.transform import resize

ImageArray= [cv2.imread(file) for file in glob.glob("Image Directory/**/*.jpg",recursive = True)]

Image1 = ImageArray[0]

# I try to resize the images based on the first image in the dataset. 

shape = Image1.shape

Other_Images_arrays = ImageArray[0:]

#I then tried to split these arrays according to the images in the dataset, but this is where I struggle and in where it makes calculating the cosine distance difficult. 

Other_Images_arrays= np.array_split(Other_Images_arrays, 29)
Other_Images_arrays_resized = resize(np.array(Other_Images_array),shape)

#Vectorising the images

Image1_vector = Image1.ravel()

Other_Images_vector= Other_Images_arrays.ravel()

Then trying to use a specific cosine function that will work

But I know that the main issue is splitting up the rest of the arrays in a suitbale manner, according to the images in the dataset.

Can anyone assist on how I split these arrays up and still be able to use them for computation?

$\endgroup$

1 Answer 1

1
$\begingroup$

Normalize the RGB values. It will, be lenth breadth X3 vector. Take cosine with every image . Find normalized similarity

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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