Question

I am using Ocelot to write a program in JavaScript Our question is below: Write a...

I am using Ocelot to write a program in JavaScript Our question is below:

Write a function called removeBlueAndGreen that takes an image as an argument and returns a red version of the input image. To do so, create a copy of the input and iterate over each pixel. If the color of a pixel is (r, g, b) in the input image, its color in the output must be (r, 0.0, 0.0).

Now is I write

let robot =

lib220.loadImageFromURL('https://www.bostondynamics.com/sites/default/files/styles/max_1300x1300/public/2019-01/MPM_9703-2.jpg?itok=7fe7RDA7');

for (let i = 0; i < robot.width; ++i) {

for (let j = 0; j < robot.height; ++j) {

robot.setPixel(i, j, [1.0, 0.0, 0.0]);

}

}

robot.show();

But the whole image is red

How would I retrieve the pixels red intensity value and make create a copy of the input and iterate over each pixel? Because with the above code I am turning each pixels red intensity to hard 1.0

Any help would be great!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You have done good so far, the only thing missing in your code is the original R value of the pixel instead of 1.

so, here goes the answer,

let robot =

lib220.loadImageFromURL('https://www.bostondynamics.com/sites/default/files/styles/max_1300x1300/public/2019-01/MPM_9703-2.jpg?itok=7fe7RDA7');

for (let i = 0; i < robot.width; ++i) {

for (let j = 0; j < robot.height; ++j) {

let c = robot.getPixel(i, j); // get the current RGB index

r_index = c[0]; // get the R index

robot.setPixel(i, j, [r_index, 0.0, 0.0]); // just change the G and B index

}

}

robot.show();

Sorry, I couldn't post any output as I am not sure which JS library you're using please share it in next questions if possible.

Add a comment
Know the answer?
Add Answer to:
I am using Ocelot to write a program in JavaScript Our question is below: Write a...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels contai...

    Please design the function in version 3 of python 4. Write a function extract(pixels, rmin, rmax, cmin, cmax) that takes the 2-D list pixels containing pixels for an image, and that creates and returns a new 2-D list that represents the portion of the original image that is specified by the other four parameters. The extracted portion of the image should consist of the pixels that fall in the intersection of the rows of pixels that begin with row rmin...

  • I am trying to create a slide show using JavaScript. This is what I have so...

    I am trying to create a slide show using JavaScript. This is what I have so far: HTML: <!DOCTYPE html> <html lang="en"> <head>    <meta charset="utf-8"> <title>Slide Show</title> <link rel="stylesheet" href="main.css"> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <script src="slide_show.js"></script> </head> <body> <section> <h1>Fishing Slide Show</h1> <ul id="image_list"> <li><a href="images/casting1.jpg" title="Casting on the Upper Kings"></a></li> <li><a href="images/casting2.jpg" title="Casting on the Lower Kings"></a></li> <li><a href="images/catchrelease.jpg" title="Catch and Release on the Big Horn"></a></li> <li><a href="images/fish.jpg" title="Catching on the South Fork"></a></li> <li><a href="images/lures.jpg" title="The Lures for Catching"></a></li> </ul>...

  • WRITE A C++ PROGRAM TO ANSWER THE QUESTIONS BELOW. You are provided with an image in...

    WRITE A C++ PROGRAM TO ANSWER THE QUESTIONS BELOW. You are provided with an image in a new file format called JBC Here is an example of the format: 2 3 100 50 40 200 66 56 12 45 65 23 67 210 0 255 100 45 32 123 The first line means that this is a 2 (width) by 3 (height) image of pixels. Then, each line represents the color of a pixel. The numbers are from 0 to...

  • I have to make a pixel art maker using javascript. HTML and CSS were already provided....

    I have to make a pixel art maker using javascript. HTML and CSS were already provided. I only had to do the JavaScript part. Every time I run the HTML folder nothing happens when I choose the width, height, and color. This is my code: (ONLY JS IS SUPPOSED TO BE FIXED). JS: // Select color input // Select size input const colorPicker = document.getElementsById('colorPicker'); const rowNum = document.getElementsById('inputHeight'); const cellNum = document.getElementById('inputWidth'); const pixelCanvas = document.getElementById('pixelCanvas'); const form =...

  • Using C++ Language This is your last assignment for this course! It is about 3D vectors...

    Using C++ Language This is your last assignment for this course! It is about 3D vectors and arrays. You can either choose to work with vectors or arrays. You don't need to do both (but, you can!). I am going to describe it using the word array. You can translate it for vectors. The dimensions of the array are 200x600x3. The datatype of the values stored in the array are unsigned char (ranges from 0 to 255). The first dimension...

  • from PIL import Image import random # NOTE: Feel free to add in any constant values...

    from PIL import Image import random # NOTE: Feel free to add in any constant values you find useful to use BLACK = (0, 0, 0) WHITE = (255, 255, 255) # NOTE: Feel free to add in any helper functions to organize your code but # do NOT rename any existing functions (or else, autograder # won't be able to find them!!) # NOTE: The following function is already completed for you as an example # You can use...

  • a) Write JavaScript code (Q4.js) that is executed when the place order button is pressed and...

    a) Write JavaScript code (Q4.js) that is executed when the place order button is pressed and it calculates the cost of each item (based on quantity specified) entered the online form and the overall total cost. The results should be displayed on the same page under the form submission button All JavaScript code must be external. If any fields are left blank or do not contain a number, an alert box should display an appropriate error message upon form submission...

  • The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have...

    The ACME Manufacturing Company has hired you to help automate their production assembly line. Cameras have been placed above a conveyer belt to enables parts on the belt to be photographed and analyzed. You are to augment the system that has been put in place by writing C code to detect the number of parts on the belt, and the positions of each object. The process by which you will do this is called Connected Component Labeling (CCL). These positions...

  • Hello, I am trying to write this program and have received a "Segmentation Fault" error but...

    Hello, I am trying to write this program and have received a "Segmentation Fault" error but cannot seem to figure out where. I haven't been able to find it and have been looking for quite a while. The goal is to basically create a version of Conway's Game of Life. I am able to generate a table if the input values for rows and columns are equal, but if they are not I receive a segmentation fault and cannot continue...

  • Please write a code in python! Define and test a function named posterize. This function expects...

    Please write a code in python! Define and test a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function, but it uses the given RGB values instead of black. images.py import tkinter import os, os.path tk = tkinter _root = None class ImageView(tk.Canvas): def __init__(self, image, title = "New Image", autoflush=False): master = tk.Toplevel(_root) master.protocol("WM_DELETE_WINDOW", self.close) tk.Canvas.__init__(self, master, width = image.getWidth(), height = image.getHeight())...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT