# How to plot an input signal in image?

Given an input signal(ex. sine) how can one go about plotting an image like below ones(the stripped black and white image)?

The images are from these slides on image processing.

Or this one:

• You need to explain where you're stuck. Your first example even includes all the Matlab code needed to make the image! Commented Nov 13, 2017 at 14:15
• Thanks. I was not clear as to how get pixel colour based on the function. It works now
– ali
Commented Nov 13, 2017 at 15:11

If you're using Python, you can use a library such as matplotlib for this. It can take a numpy array and plot it as a standard chart using the function plot or as an image using imshow. The resulting image/plot can be displayed in an interactive window, or saved to a file, or it shows inline in your Jupyter notebook if you're using that.

There are other (better?) Python chart plotting libraries but the functionality is basic and IMO matplotlib is easier to get started with (perhaps just because it's older and more established).

You can also do this using OpenCV, if your input is an OpenCV image. Its plotting functions are named similarly to the matplotlib ones. OpenCV is available in Python, C++, and a handful of other languages.

• Thank you for the answer. but what is the algorithm if I one wants to implement it and not using 3rd parties? I use c# language.
– ali
Commented Nov 13, 2017 at 10:18
• Just to note that my question referred to how the black and white stripped image is created given the sine or whatever signal.
– ali
Commented Nov 13, 2017 at 10:28
• In that case, could you edit your question and make it clearer? Regardless of language, the short answer is "make an array of values from your function and then convert it into the image type you're using". Commented Nov 13, 2017 at 10:40
• Sorry about the question not being clear enough. I have updated it. I still don't understand how to do it could you give an example please.
– ali
Commented Nov 13, 2017 at 12:04