Open In App

What is Glassy Effect in MATLAB?

Last Updated : 22 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. With the help of this software, we can also give the glassy effect to an image. It is done by replacing each pixel value in the image with a random value from one of its 
neighbors, including self, in an m by n window. 

The Glassy effect is a filter that is used to give a blurry or real-looking glass surface image.

Steps:

Steps to create a glassy effect image using MATLAB Software.

  1. Read the original image using imread and show it with the title ‘Original Image’.
  2. Now we’ll define a window of size m by n.
  3. Now we’ll use nested for loops and select a random pixel value from its neighbors.
  4. In the last step, we’ll save the image with the glassy effect and show it with the title Blurry Image.

Example 1:

Matlab




% MATLAB code for Glassy Effect
% reading the image
original=imread('image.png');
imshow(original);title('Original Image');
  
% Window size of m by n
m=6;                                                                  
n=7;
BlurredImage = uint8(zeros([size(original,1)-m,size(original,2)-n,3]));
  
  
% Nested for loop
for i = 1:(size(original,1)-m)
    for j = 1:(size(original,2)-n)
        temp = original(i:i+m-1 , j:j+n-1, :);
        % select a random pixel's value from the neighbourhood
        newX = ceil(rand(1)*m);
        newY = ceil(rand(1)*n);
        % giving blurred image its value
        BlurredImage(i,j,:) = temp(newX, newY, :);
    end
end
  
% Showing blurry image in figure 2
figure, imshow(BlurredImage); title('Blurry Image');
  
% Saving the image with the glassy effect
imwrite(BlurredImage, 'Blurry Image.png');


Output:

Sample image:

 

Output Image:

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads