Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Image comparision using opencv

$
0
0

MY Code is Following -:

So basically I have to highlight the changes or areas of discrepancy between the two images.

image1

image2

from pdf2image import convert_from_path # Used to convert pdf to imageimport cv2import numpy as npfrom PIL import Image, ImageOpsfrom IPython.display import displaydef process_and_display_image(pdf_path, target_size=(800, 600),save_path='processed_image.jpeg'):    # Convert PDF to image    images = convert_from_path(pdf_path)    # Since there is only 1 image in the pdf    image = images[0]    # Automatically rotates the image if needed    image = ImageOps.exif_transpose(image)    # Resize image to target size    image.thumbnail(target_size, Image.Resampling.LANCZOS)    # Convert to numpy array for any advanced processing    image_np = np.array(image)    # Converting to grayscale to reduce variations    image_np = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)    # Convert back to PIL image to display in Jupyter    image_processed = Image.fromarray(image_np)    # Display the processed image    display(image_processed)    # Save the processed image to a file    image_processed.save(save_path, 'JPEG')    print(f"Image saved as {save_path}")import matplotlib.pyplot as plt# Read the imageimage1 = cv2.imread('file_1.jpeg', cv2.IMREAD_UNCHANGED)# Convert the image from BGR to RGB image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2RGB)image2 = cv2.imread('file_2.jpeg', cv2.IMREAD_UNCHANGED)image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2RGB)if image1.shape == image2.shape:    difference = cv2.absdiff(image1,image2)    difference = cv2.cvtColor(difference, cv2.COLOR_BGR2RGB)    b,g,r=cv2.split(difference)plt.imshow(difference)plt.axis('off')plt.show()

My output image is coming out to be

my_output

But I want my output image to be likedesired_output

Please Help me


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>