Question
I need a matlab code to implement tne rest of the project without using any of the matlab image processing toolbox or presettings. # count
I need a matlab code to implement tne rest of the project without using any of the matlab image processing toolbox or presettings.
# count the new grey level in position(i,j) | |
def spatial_filtering(i, j): | |
# create a s*s array to represent the pixels that have | |
# influence on position(i,j)'s new grey level | |
array = [[(0,0)] * s ] * s | |
average = 0 | |
| |
# count the coordinate of the s*s pixels | |
for a in range(s): | |
for b in range(s): | |
x = i + dis[a] | |
y = j + dis[b] | |
| |
# if the pixel's position is out of the image's range | |
# set it to the boundary's value | |
if(x | |
x = 0 | |
if(y | |
y = 0 | |
if(x >= width): | |
x = width - 1 | |
if(y >= height): | |
y = height - 1 | |
| |
# keep the array for better understanding, it can be deleted | |
array[a][b] = ( x, y ) | |
#count the average of the s*s pixels' grey level | |
average += data[array[a][b]] | |
| |
average = average / (s * s) | |
| |
#return average | |
return average | |
| |
# open an image and get its information | |
im = Image.open('Fig0219(rose1024).tif') | |
data = im.load() | |
width, height = im.size | |
MN = width * height | |
| |
# new two blank images for rewrite and downsampling | |
resultImage = Image.new('L',(width, height), 'white') | |
| |
# count the frequency of each grey level | |
s = input('please input size: ') | |
dis = [0] * s | |
| |
for c in range(s): | |
dis[c] = c - (s / 2) | |
| |
# draw the new HE image | |
draw = ImageDraw.Draw(resultImage) | |
| |
#width = height = 10 | |
for i in range(width): | |
for j in range(height): | |
# for each pixel, find its corresponding grey level after HE | |
p = spatial_filtering(i, j) | |
draw.point((i, j), p) | |
| |
filename = 'SFImage_rose_blursize=' + str(s) + '.bmp' | |
| |
#save the output files | |
resultImage.save(filename, format='BMP') |
PROJECT 4- SPATIAL DOMAIN IMAGE PROCESSING Spatial Filtering Write program to perform spatial filtering of an image (see Section 3.4 regarding implementation). You can fix the size ofthe spatial mask at 3x3, but the coefficients need to be variables that can be input into yourprogram. This project is generic, in the sense that it will be used in other projects to fo llow Enhancement Using the Laplacian (a) Use the programs developed above (and in Project 2)to implement the Laplacian enh ancement technique descrbed in connection with Eq. (3.6-6). Use the mask shown in Fig. 3.37(d). (b)Duplicate the results in Fig. 3.38. You will need to download Fig0338(a)(blurry moon). Unsharp Masking (a) Use the programs developed above (and in Project 2)to implement high-boost filtering, as given in Eqs. (3.6-8,3.6-9). The averaging part of the process should be done using the mask in Fig. 3.32 (a). (b)Download Fig0340(a)(dipxe text) an d enhance it using the program you developed in (a). Your objective is to choose constant k so that your result visually approximates Fig. 3.40(e). PROJECT 4- SPATIAL DOMAIN IMAGE PROCESSING Spatial Filtering Write program to perform spatial filtering of an image (see Section 3.4 regarding implementation). You can fix the size ofthe spatial mask at 3x3, but the coefficients need to be variables that can be input into yourprogram. This project is generic, in the sense that it will be used in other projects to fo llow Enhancement Using the Laplacian (a) Use the programs developed above (and in Project 2)to implement the Laplacian enh ancement technique descrbed in connection with Eq. (3.6-6). Use the mask shown in Fig. 3.37(d). (b)Duplicate the results in Fig. 3.38. You will need to download Fig0338(a)(blurry moon). Unsharp Masking (a) Use the programs developed above (and in Project 2)to implement high-boost filtering, as given in Eqs. (3.6-8,3.6-9). The averaging part of the process should be done using the mask in Fig. 3.32 (a). (b)Download Fig0340(a)(dipxe text) an d enhance it using the program you developed in (a). Your objective is to choose constant k so that your result visually approximates Fig. 3.40(e)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started