BACKGROUND

In case if you don’t know, Matlab means “Matrix Laboratory”, which is a high-performance language to compute basic and advance technical problems in an easy way. Adobe Photoshop is a software that provides different kind of image editing features, graphic design, and digital art.


DIGITAL IMAGE PROCESSING (DIP)

Digital Image processing (DIP) is not limited to only adjusting your picture brightness and contrast, and apply some filters to it before you upload it to your Instagram. NO! It’s far more than that. Digital Image Processing is a method to convert an image from analog to digital and perform some process to it to gain new and useful information from it. There are a lot of applications of image processing in various areas, for example computerized photography, space image processing, medical and biological industries, finger or face recognition, and many more. Below is the summary of simple diagram to make you understand on how the Digital Image Processing works:


Image > Analog to Digital converter > processor > Digital to Analog converter > display


I am inspired to write about Image Processing based on the articles that I read on MathWorks website about Steve on Image Processing where he wrote codes in Matlab to edit all his travel photos and named his article as “Don’t Photoshop it… Matlab it!”. He challenged himself to process his images in Matlab by using Image Processing Toolbox. Basically, by using Matlab, he was able to create new and free effects to enhance his images. So, I will share with you some simple ways to edit your pictures in Matlab based from what I have learnt in Lab 10a.


MATLAB CODE

LOAD IMAGE TO MATLAB

A = imread('image.tif');  %Use Imread command to load your image into your Matlab space

B = double(A); %Make sure you change your image type from uint8 to double by using double command


figure %This will show you the image that you load to your Matlab workspace

image(B);

colormap(gray(256));

axis('image');

title("Original");


HOW TO FLIP YOUR IMAGE HORIZONTALLY

B_hori = B(:, end:-1:1, :);

figure

image(B_hori)

colormap(gray(256));

axis('image');

title("Horizontal");


HOW TO FLIP YOUR IMAGE VERTICALLY

B_ver = B(end:-1:1,:,:);

figure

image(B_ver)

colormap(gray(256));

axis('image');

title("Vertical")


You can also use imrotate command to rotate your photo. Here’s the example of it:

image_rotate = imrotate(B, -90);

You can change to 90, 180, 270, or anyway you like by using that command.


HOW TO CHANGE YOUR IMAGE TO NEGATIVE

[k, l] = size(B); for m = 1:k

  for n = 1:l
      B_neg(m, n) = 255 - B(m, n);
  end

end


figure

image(B_neg)

colormap(gray(256));

axis('image');

title("Negative")


HOW TO ENHANCE YOUR IMAGE COLOR

You can use imadjust to enhance your color adjustment of your picture in Matlab. Here’s how it works:

Output = imadjust(input);


OR


Output = imadjust(input, [low_in; high in], [low_out; high_out], gamma);

You can adjust the value of low_in, high_in, low_out and high_out to get different output from it.


HOW TO DO GAMMA CORRECTION

A = imread(‘image.tif’)

B = double(A);

[row col] = size(B);

gamma = 2.2;  % you can setup any value based on output that you want


for m = 1:1:row;

  for n = 1:1:col;
      x = B(m, n);
      corrected(m, n) = 255 * ((x / 255) ^ (1 / gamma));  
  end

end


figure

image(corrected)

colormap(gray(256));

axis(‘image’);

title(“Image after Gamma Correction”)


CONCLUSION

There are a lot more ways and technique to do image processing in Matlab and it will take hours or days to describe more about it. I hope you learn something new from what I wrote. If you have too much free time and you feel like you want to upload a photo on Instagram, try spending your winter by editing your photo in Matlab and play around with it before upload it. It will be so much fun and you will be proud of yourself! Before I end, I like to quote Mr. Woohoo (aka Drew Trujillo) that has used Matlab and Photoshop into another different level. He uses Photoshop feature that can interface his software with Matlab to extending his art.

“For me, it simply means that we can now ‘drive’ Photoshop by writing code in Matlab while taking advantage of a very powerful engine with a superior supporting set of libraries (called Toolboxes). Think of Matlab as giving you the ability to write your own plug-ins for Photoshop.”


SOURCES

[1] PHOTOSHOP + MATLAB = ART, http://blogs.adobe.com/jnack/2007/06/photoshopmatlabart.html

[2] DON'T PHOTOSHOP IT... MATLAB IT! IMAGE EFFECTS WITH MATLAB (PART 1 - PART 4), https://blogs.mathworks.com/steve/2012/11/13/image-effects-part-1/

[3] ECE 438 LAB 10 A, https://engineering.purdue.edu/VISE/ee438L/lab10/pdf/lab10a.pdf

[4] LECTURE NOTES

[5] APPLICATIONS AND USAGE OF IMAGE PROCESSING, https://www.tutorialspoint.com/dip/applications_and_usage.htm

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett