Question

Write the function compute_histogram, in Matlab, that takes a grayscale image as input and returns a...

Write the function compute_histogram, in Matlab, that takes a grayscale image as input and returns a length 256 vector h which is the normalized histogram of the values in the image. h should have values from 0 to 1 and its components should sum to 1.

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

function [h]=compute_histogram(img)
[n,m] = size(img);
h = zeros(562);
for i =1:n
for j =1:m
h(img(i,j)) = h(img(i,j))+1;
end
end
% normalize
total_pixel=n*m;
h=h./total_pixel;

end

main.m

img = imread('pandu562.png');
figure(1);
imshow(img);
h = compute_histogram(img);
figure(2);
bar(h,1,'b');

0.012 0.01 0.008 0.006 0.004 0.002 50 100 150 200 250 300

Add a comment
Know the answer?
Add Answer to:
Write the function compute_histogram, in Matlab, that takes a grayscale image as input and returns 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
  • MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when c...

    MATLAB QUESTION Write a MATLAB function called vector_input that takes no inputs and returns no outputs. Instead, when called, it gives control to the user and asks the user to input a length-3 vector. Then the function prints: The sum of ___, ____, and ____ is ____. [new line] where the first three blanks are filled by each element in input vector, and the last blank is the sum of all three elements.

  • MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the...

    MATLAB Write a function maxContent(arr) that takes a cell array arr as input and returns the longest string and largest number in arr. If there are two character arrays of same length, the function should return one of them. Assume that integers in the cell array are nonnegative.

  • Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as...

    Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...

  • How do you convert an RGB image to grayscale in matlab using array manipulation. Please dont...

    How do you convert an RGB image to grayscale in matlab using array manipulation. Please dont use grayscale function to do this. First you should go to each pixek to get the mean value and set all three layers to that mean value matlab code please write the simplest and shortest code using array manipulation. And please dont use a function for grayscale

  • Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr,...

    Matlab: Write a function called minimax that takes M, a matrix input argument and returns mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row. As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix. See the code below for an example: >> A = randi(100,3,4) A = 66 94 75 18 4 68 40 71 85 76...

  • b) (2.5 marks) Write a Matlab user defined function that takes the letter grades (i.e. AABBC) as input and returns...

    b) (2.5 marks) Write a Matlab user defined function that takes the letter grades (i.e. AABBC) as input and returns if the student entitled to the honor list or not. The student is considered in the honor s f he or she satisfies the following three conditions: a. An average GPA of 3.5 and above and b. At least two classes with A mark and e. no class with a mark less than C (i.e. no D or F) The...

  • Please use matlab to code this program. Write a computer program that takes as input an angle β and the components of a...

    Please use matlab to code this program. Write a computer program that takes as input an angle β and the components of a position vector in frame A (i.e. r). The transformation from frame A to frame B is a rotation about the 1-axis. Your code should calculate the DCM CAB, and the components of the vector in frame B (i.e.rB. Your code should output all of the following, including a label and units (if applicable) for each: CAB 4.8...

  • This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an...

    This code NEEDS TO BE DONE IN MATLAB!!!! Write a function that takes one input, an integer number n, and returns a matrix that is nxn, where the value of each number is the distance from the upper-left to bottom-right diagonal. (Use while loops if you can!) Numbers below the diagonal should be negative, and numbers above the diagonal should be positive. For example, if your input was 5, your output would be: 0 1 2 3 4 -1 0...

  • Write a stored function that takes a number as its input and returns that number as...

    Write a stored function that takes a number as its input and returns that number as currency, i.e. it should have a leading dollar sign, only have two decimal places, and have commas for the thousands. If the number is negative the result should be in parenthesis, accounting format, -123.45 returns ($123.45). If the input is a non-number, e.g. “Hello”, the function should return $0.00

  • Repost pls show clear and correct codes in matlab.. Question 2. Write a MATLAB Function my-fun...

    Repost pls show clear and correct codes in matlab.. Question 2. Write a MATLAB Function my-fun that takes as its input a vector of numeric values nums and returns a vector whose values are exactly/only the indicies of nums whose values are non- zero. You may not use any built-in MATLAB functions - i.e. find Sample call(s): CALL 1: my-fun( [8 05 0] ) \% would evaluate [1 3] CALL 2: my-fun ( [0 9 0 1 0] ) \%...

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