Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

matlab to python Please change this MATLAB code to Python code (You only need to change the functional part.) clear all %READ THE RGB IMAGE

matlab to python

Please change this MATLAB code to Python code (You only need to change the functional part.)

clear all

%READ THE RGB IMAGE

I = imread('peppers.png');

A = imnoise(I,'Salt & pepper',0.1);

figure,imshow(A);title('IMAGE WITH SALT AND PEPPER NOISE');

%DEFINE THE WINDOW SIZE MXN

M=3;

N=3;

%PAD THE MATRIX WITH ZEROS ON ALL SIDES

modifyA=padarray(A,[floor(M/2),floor(N/2)]);

B = zeros([size(A,1) size(A,2)]);

med_indx = round((M*N)/2); %MEDIAN INDEX

for i = 1:size(modifyA,1)-(M-1)

for j = 1:size(modifyA,2)-(N-1)

temp = modifyA(i:i+(M-1),j:j+(N-1),:);

%RED,GREEN AND BLUE CHANNELS ARE TRAVERSED SEPARATELY

for k = 1:3

tmp = temp(:,:,k);

B(i,j,k) = median(tmp(:));

end

end

end

%CONVERT THE IMAGE TO UINT8 FORMAT.

B = uint8(B);

figure,imshow(B);

title('IMAGE AFTER MEDIAN FILTERING');

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions

Question

What are dimensionless figures?

Answered: 1 week ago