[Solved] CS484 Homework 1 Questions

$25

File Name: CS484_Homework_1_Questions.zip
File Size: 244.92 KB

SKU: [Solved] CS484 Homework 1 Questions Category: Tag:
5/5 - (1 vote)

Questions

Q1: We wish to set all pixels that have a brightness of 10 or less to 0, to remove sensor noise. However, our code is slow when run on a database with 1000 grayscale images. Image: grizzlypeakg.png

import cv2 import numpy as np

A = cv2.imread(grizzlypeakg.png,0) m1, n1 = A.shape for i in range(m1):

for j in range(n1):

if A[i,j] <= 10: A[i,j] = 0

Q1.1: How could we speed it up?

A1.1: Use logical indexing.

import cv2 import numpy as np

  • = cv2.imread(grizzlypeakg.png,0)
  • = A <= 10A[B] = 0

Q1.2: What factor speedup would we receive over 1000 images? Please measure it.

Ignore file loading; assume all images are equal resolution; dont assume that the time taken for one image 1000 will equal 1000 image computations, as single short tasks on multitasking computers often take variable time. A1.2: Factor speedup: 882.9766897090233

Q1.3: How might a speeded-up version change for color images? Please measure it.

Image: grizzlypeak.jpg

A1.3: Factor speedup: 292.8242565864542

Q2: We wish to reduce the brightness of an image but, when trying to visualize the result, we see a brightness-reduced scene with some weird corruption of color patches. Image: gigi.jpg

import cv2 import numpy as np

I = cv2.imread(gigi.jpg).astype(np.uint8)

I = I 40

cv2.imwrite(result.png, I)

Q2.1: What is incorrect with this approach? How can it be fixed while maintaining the same amount of brightness reduction?

A2.1: Substituting the brightness by 40 for all pixels is incorrect as underflow corrupted the result. It can be fixed by setting pixels with original brightness less than 40 as 0, as code in the below.

import cv2 import numpy as np

I = cv2.imread(gigi.jpg).astype(np.uint8)

B = I < 40

I = I 40

I[B] = 0

cv2.imwrite(result.png, I)

Q2.2: Where did the original corruption come from? Which specific values in the original image did it represent?

A2.2: The original corruption came from pixels with original brightness less than 40, as they cause underflow if substituting by 40.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS484 Homework 1 Questions[Solved] CS484 Homework 1 Questions
$25