A3_1
.py
keyboard_arrow_up
School
Arizona State University *
*We aren’t endorsed by this school
Course
509
Subject
Electrical Engineering
Date
Dec 6, 2023
Type
py
Pages
3
Uploaded by SuperHumanOstrich3671 on coursehero.com
import numpy as np
import cv2
from skimage.metrics import structural_similarity as ssim
from skimage.metrics import mean_squared_error, peak_signal_noise_ratio
import matplotlib.pyplot as plt
import random
# Step 1: Load the original Nadia image
nadia_original = cv2.imread('nadia_orig.png', cv2.IMREAD_GRAYSCALE)
# Step 2: Create images with impulse noise and structural distortions
def add_impulse_noise(image, noise_ratio):
output = np.zeros(image.shape, np.uint8)
thres = 1 - noise_ratio
for i in range(image.shape[0]):
for j in range(image.shape[1]):
rdn = random.random()
if rdn > thres:
output[i][j] = 255
else:
output[i][j] = image[i][j]
return output
# noisy_image = image.copy()
# total_pixels = image.size
# num_noisy_pixels = int(noise_ratio * total_pixels)
# indices = np.random.choice(total_pixels, num_noisy_pixels, replace=False)
# noisy_image.flat[indices] = 255
# return noisy_image
def introduce_structural_distortions(image):
distorted_image = image.copy()
left = 70
top = 150
right = 330
bottom = 320
roi = distorted_image[top:bottom, left:right]
scaled_section = cv2.resize(roi,
(distorted_image.shape[1],
int((distorted_image.shape[1] / roi.shape[1]) * roi.shape[0])),
interpolation=cv2.INTER_AREA)
scaled_height, scaled_width = scaled_section.shape[:2]
distorted_image[top - 50:top - 50 + scaled_height, 0:distorted_image.shape[1]]
= scaled_section
left_n = 120
top_n = top - 50 + scaled_height
right_n = 320
bottom_n = top - 50 + scaled_height + 150
scaling_factor_zoom_out = 0.8
roi = distorted_image[top_n:bottom_n, left_n:right_n]
zoomed_out_section = cv2.resize(roi, None, fx=scaling_factor_zoom_out,
fy=scaling_factor_zoom_out,
interpolation=cv2.INTER_AREA)
zoomed_out_height, zoomed_out_width = zoomed_out_section.shape[:2]
distorted_image[top_n:top_n + zoomed_out_height, left_n:left_n +
zoomed_out_width] = zoomed_out_section
return distorted_image
noise_ratio = 0.395
# Adjust as needed
impulse_noisy_nadia = add_impulse_noise(nadia_original, noise_ratio)
structurally_distorted_nadia = introduce_structural_distortions(nadia_original)
# Add very tiny amount of noise
tiny_noise_ratio = 0.00028 # Adjust as needed
tiny_noisy_nadia = add_impulse_noise(nadia_original, tiny_noise_ratio)
# Step 3: Calculate SSIM and MSE
def calculate_metrics(original, distorted):
ssim_score = ssim(original, distorted)
mse_score = mean_squared_error(original, distorted)
return ssim_score, mse_score
# Calculate SSIM & MSE
ssim_impulse_noisy, mse_impulse_noisy = calculate_metrics(nadia_original,
impulse_noisy_nadia)
ssim_structurally_distorted, mse_structurally_distorted =
calculate_metrics(nadia_original,
structurally_distorted_nadia)
ssim_tiny_noisy, mse_tiny_noisy = calculate_metrics(nadia_original,
tiny_noisy_nadia)
# Calculate PSNR
psnr_impulse_noisy = peak_signal_noise_ratio(nadia_original, impulse_noisy_nadia)
psnr_structurally_distorted = peak_signal_noise_ratio(nadia_original,
structurally_distorted_nadia)
psnr_tiny_noisy = peak_signal_noise_ratio(nadia_original, tiny_noisy_nadia)
# Display the images with metrics
plt.figure(figsize=(12, 8))
# Original Nadia Image
plt.subplot(141)
plt.imshow(nadia_original, cmap='gray')
plt.title('Original Nadia Image')
plt.axis('off')
# Impulse Noisy Nadia Image
plt.subplot(142)
plt.imshow(impulse_noisy_nadia, cmap='gray')
plt.title(
f'Impulse Noisy Nadia\nMSE: {mse_impulse_noisy:.4f}, \nPSNR:
{psnr_impulse_noisy:.4f}, \nSSIM: {ssim_impulse_noisy:.4f}')
plt.axis('off')
# Structurally Distorted Nadia Image
plt.subplot(143)
plt.imshow(structurally_distorted_nadia, cmap='gray')
plt.title(
f'Structurally Distorted Nadia\nMSE: {mse_structurally_distorted:.4f}, \nPSNR:
{psnr_structurally_distorted:.4f}, \nSSIM: {ssim_structurally_distorted:.4f}')
plt.axis('off')
# Tiny Noisy Nadia Image
plt.subplot(144)
plt.imshow(tiny_noisy_nadia, cmap='gray')
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
Need this answered in Canonical POS form (using the highlighted 0's) in the attached screen shot table first, then to covert to minimized SOP form.
I don't understand how to convert from
Canonical POS form below listed as from the screen shot chart... to minimized SOP form.
a.) Y = (A'+B'+C)(A'+B+C)(A+B'+C')(A+B+C')
b.) W = (A+B'+C')(A+B'+C)(A+B+C')+(A+B+C)
arrow_forward
subject DLD
plzz solve urgent with complete detail.. thnx
arrow_forward
https://www.chegg.com/homework-help/questions-and-answers/-given-p-k-045-p-l-027-p-kol-013-draw-venn-diagram-fill-probabilities-determine-following--q60199359
arrow_forward
Compute the 8 – point DFT of x(n) = { 1,2,3,0,3,2,1,3}, using the following methods;(a) DIT – FFT method (b) DIF – FFT method (c) Phasor plot of twiddle factor to compute the DFT
arrow_forward
Determine the transfer function matrix
will give good rating if detailed solution, need answer urgently. thank you
arrow_forward
Super position theorem please
arrow_forward
subject DLD
plzz solve urgent with complete details
thnx
arrow_forward
For Routh Stability Criterion, Answer the following questions:
1. If the sign of the coefficient above the zero is the same as that below it?
I. There is a pair of imaginary roots
II. There is one sign change.
III. There are roots of equal magnitude lying radially opposite in the S-Plane.
IV. There is a root or roots that are imaginary or that have positive real parts.
2. If the sign of the coefficient above the zero is opposite of that below it?
I. There is a pair of imaginary roots.
II. There is one sign change.
III. There is one sign change.
IV. There is a root or roots that are imaginary or that have positive real parts.
arrow_forward
For the circuit shown, let IBIAS = 0.5 mA, RL1 = 1.5 kOhms and RL2 = 1.5 kOhms. What are the values of VO1 and VO2?
arrow_forward
An asynchronous circuit has two SR latches (not edge-triggered FF) denoted SR1 and SR2, and two external inputs x1 and x2. It also has a single output z. The excitation expressions for the inputs and output equations are (see image).
Using the characteristic equation for an SR latch, draw the excitation table. Then draw the state table, flow table, and flow diagram.
arrow_forward
a) Sketch the root locusb) Using Routh-Hurwitz, determine the maximum gain Kp before system goesunstable
arrow_forward
Need Asap with Clear Explanation step by ? Step
arrow_forward
with the KMAP provided (attached) write a simplified equation for Y.
please explain the kmap simplification SOP process and create circles kmap.
arrow_forward
Using K-Maps, find the best SOP (Sum of Products) and POS (Sums Product) solution of the following function: its in the image
Note: The list at the end is the unimportant X's.Tip for POS: Take no letters (or not regions) that appear in KMap, zeros are included, answer is found. Please do not use KMap other than the one below.
arrow_forward
Can you solve the option d? here are the answers to the previous questions;
https://www.bartleby.com/questions-and-answers/question-4.-we-have-a-biomedical-measurement-set-up-that-can-be-modeled-as-a-second-order-system-wit/8d0d1bf1-2322-4991-a613-8c6cee44ec8a
arrow_forward
please solve proper step by step subject signal and systems
arrow_forward
The subject is Communication Systems ( A RANDOM SIGNAL GENERATION AND ANALYSIS )
Please send the answer by typing i don't want any handretten.
Q1.... [Explain SNR (Signal to noise ratio)]?
arrow_forward
What is maximum power transfer theorem in brief
arrow_forward
Please solveit fast
arrow_forward
Please solve this problem i will give likess
arrow_forward
circuits, pleaseeeee solve questionnn10
arrow_forward
Solve the below problem quickly as soon as possible.
arrow_forward
Consider the following plots of time-domain and frequency-domain signals. Label the axes of the five plots. For example, plot B should be labeled as amplitude vs. time. Characterize each plot as either a time-domain or a frequency-domain signal.
Describe the mathematical relationships among the plots. For example, how could you arrive at plot A from plots D and E?
arrow_forward
Pls solve neatly and step by step
arrow_forward
The subject is Communication Systems ( PSK MODULATION )
Please send the answer by typing i don't want any handwritten.
Q3)Explain phase modulation?and give some applications of BPSK
arrow_forward
Write examples of random and deterministic signals in physiological systems.
arrow_forward
Simplify the following expression into sum of products using Karnaugh map
F(A,B,C,D) = ∑(1,3,4,5,6,7,9,12,13)
arrow_forward
This the Syllabus:
Module No. 1 Neural Networks
History, Mathematical model of neuron, ANN architectures, Learning rules, Learning
Paradigms. Perceptron network, Backpropagation network, Backpropagation learning and its
applications, Variants of BPA.
Module No. 2
Associative Memory: Auto Hetero , Exponential BAM, Applications.
arrow_forward
1)Given Kp=40uA/V2, VTP=-3V,VSG=2V, VSD=2V, compute IDP
2)Given Kp=404A/V2, VTP=-3V,VSG=2V, VSD=2V, compute IDP
3)Given Kp=40uA/V2, VTP=-IV,VSG=3V, VSD=5V, compute IDP
4)Given Kp=50uA/V2, VTP=-5V,VSG=4V, VSD=5V, compute ID
5)Given Kp=50uA/V2, VTP=-1V,VSG=0V, VSD=5V, compute ID
arrow_forward
I solved it in frequency-domain way. And answer is correct. But didn't get point, Can you explain why should I use this way to solve it? More details. Thank you! As soon as possible!
(Don't just copy an answer from another website)
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Power System Analysis and Design (MindTap Course ...
Electrical Engineering
ISBN:9781305632134
Author:J. Duncan Glover, Thomas Overbye, Mulukutla S. Sarma
Publisher:Cengage Learning
Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning
Related Questions
- Need this answered in Canonical POS form (using the highlighted 0's) in the attached screen shot table first, then to covert to minimized SOP form. I don't understand how to convert from Canonical POS form below listed as from the screen shot chart... to minimized SOP form. a.) Y = (A'+B'+C)(A'+B+C)(A+B'+C')(A+B+C') b.) W = (A+B'+C')(A+B'+C)(A+B+C')+(A+B+C)arrow_forwardsubject DLD plzz solve urgent with complete detail.. thnxarrow_forwardhttps://www.chegg.com/homework-help/questions-and-answers/-given-p-k-045-p-l-027-p-kol-013-draw-venn-diagram-fill-probabilities-determine-following--q60199359arrow_forward
- Compute the 8 – point DFT of x(n) = { 1,2,3,0,3,2,1,3}, using the following methods;(a) DIT – FFT method (b) DIF – FFT method (c) Phasor plot of twiddle factor to compute the DFTarrow_forwardDetermine the transfer function matrix will give good rating if detailed solution, need answer urgently. thank youarrow_forwardSuper position theorem pleasearrow_forward
- subject DLD plzz solve urgent with complete details thnxarrow_forwardFor Routh Stability Criterion, Answer the following questions: 1. If the sign of the coefficient above the zero is the same as that below it? I. There is a pair of imaginary roots II. There is one sign change. III. There are roots of equal magnitude lying radially opposite in the S-Plane. IV. There is a root or roots that are imaginary or that have positive real parts. 2. If the sign of the coefficient above the zero is opposite of that below it? I. There is a pair of imaginary roots. II. There is one sign change. III. There is one sign change. IV. There is a root or roots that are imaginary or that have positive real parts.arrow_forwardFor the circuit shown, let IBIAS = 0.5 mA, RL1 = 1.5 kOhms and RL2 = 1.5 kOhms. What are the values of VO1 and VO2?arrow_forward
- An asynchronous circuit has two SR latches (not edge-triggered FF) denoted SR1 and SR2, and two external inputs x1 and x2. It also has a single output z. The excitation expressions for the inputs and output equations are (see image). Using the characteristic equation for an SR latch, draw the excitation table. Then draw the state table, flow table, and flow diagram.arrow_forwarda) Sketch the root locusb) Using Routh-Hurwitz, determine the maximum gain Kp before system goesunstablearrow_forwardNeed Asap with Clear Explanation step by ? Steparrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Power System Analysis and Design (MindTap Course ...Electrical EngineeringISBN:9781305632134Author:J. Duncan Glover, Thomas Overbye, Mulukutla S. SarmaPublisher:Cengage LearningElectricity for Refrigeration, Heating, and Air C...Mechanical EngineeringISBN:9781337399128Author:Russell E. SmithPublisher:Cengage Learning
Power System Analysis and Design (MindTap Course ...
Electrical Engineering
ISBN:9781305632134
Author:J. Duncan Glover, Thomas Overbye, Mulukutla S. Sarma
Publisher:Cengage Learning
Electricity for Refrigeration, Heating, and Air C...
Mechanical Engineering
ISBN:9781337399128
Author:Russell E. Smith
Publisher:Cengage Learning