Question

Write a program that creates an image of green and white horizontal stripes. Your program should...

Write a program that creates an image of green and white horizontal stripes. Your program should ask the user for the size of your image, the name of the output file, and create a .png file of stripes. For example, if the user enters 10, your program should create a 10x10 image, alternating between green and white stripes.

A sample run of the program:

  Enter the size: 10
  Enter output file: 10stripes.png
  


Another sample run of the program:

  Enter the size: 50
  Enter output file: 50stripes.png
  


To create an image from scratch:

1 Import the libraries.

import matplotlib.pyplot as plt

import numpy as np

2 Create the image–

easy to set all color 1 to 0% (black): img = np.zeros( (num,num,3) )

2 to 100% (white): img = np.ones( (num,num,3) )

3 Do stuff to the pixels to make your image

4 You can display your image:

plt.imshow(img)

plt.show()

5 And save your image:

plt.imsave(’myImage.png’, img)

Homework Answers

Answer #1

Python code:

import matplotlib.pyplot as plt

import numpy as np

size = int(input("Enter the size: "))

fname = str(input("Enter output file: "))

#Initialize Image as white color with value 1 in all the pixel

img = np.ones( (size,size,3) )

for i in range(1,size,2):

for j in range(size):

img[i][j][1] = 1

img[i][j][0] = 0

img[i][j][2] = 0

plt.imsave(fname, img)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a python program that takes in an image from the user and puts the image...
Create a python program that takes in an image from the user and puts the image into matrices of red, green, and blue. Then use the equation Y = 0.2126R + 0.7125G + 0.0722B to convert the image to grayscale and output the grayscale image. You must only use the libraries numpy, matplotlib.pyplot, and math. You may not use pillow, openCV, sciPy, etc.
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Complete the following program. This program should do the following: 1. Creates a random integer in...
Complete the following program. This program should do the following: 1. Creates a random integer in the range 10 to 15 for variable: allThreads, to create a number of threads. 2. Creates a random integer for the size of an ArrayList: size. 3. Each thread obtains a smallest number of a segment of the array. To give qual sized segment to each thread we make the size of the array divisible by the number of threads: while(size%allThreads != 0)size++ 4....
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
The second assignment will use C++ syntax and control flow stuctures (e.g. loops, switch statements, functions,...
The second assignment will use C++ syntax and control flow stuctures (e.g. loops, switch statements, functions, const int variables, structs, the standard library, enums, array, etc.) to create a pattern drawing application. A user of your application will be able to select a shape to draw that will be printed out to standard output using std::cout. This application will draw a fixed size 8x8 pattern. The patterns your application will support are: filled, half-left filled, banded, checkered, a square, an...
IN JAVA Speed Control Problem: The files SpeedControl.java and SpeedControlPanel.java contain a program (and its associated...
IN JAVA Speed Control Problem: The files SpeedControl.java and SpeedControlPanel.java contain a program (and its associated panel) with a circle that moves on the panel and rebounds from the edges. (NOTE: the program is derived from Listing 8.15 and 8.16 in the text. That program uses an image rather than a circle. You may have used it in an earlier lab on animation.) The Circle class is in the file Circle.java. Save the program to your directory and run it...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT