Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6812279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:25:48+00:00 2026-05-26T20:25:48+00:00

I am using FreeMat , and I have an RGB picture which is a

  • 0

I am using FreeMat, and I have an RGB picture which is a 3D matrix contains the columns and rows of the pictures and the RGB values for each pixel.

Since there is not an intrinsic function to convert RGB picture to YIQ, I have implement one. I came up with this code:

Assume I have a 3D array, image_rgb:

matrix = [0.299 0.587 0.114;
0.596 -0.274 -0.322;
0.211 -0.523 0.312];
row = 1:length(image_rgb(:,1,1));
col = 1:length(image_rgb(1,:,1));
p = image_rgb(row,col,:);

%Here I have the problem
mage_yiq(row,col,:) = matrix*image_rgb(row,col,:);

max_y = max (max(image_yiq(:,:,1)));
max_i = max (max(image_yiq(:,:,2)));
max_q = max (max(image_yiq(:,:,3)));

%Renormalize the image again after the multipication
% to [0,1].
image_yiq(:,:,1) = image_yiq(:,:,1)/max_y;
image_yiq(:,:,2) = image_yiq(:,:,2)/max_i;
image_yiq(:,:,3) = image_yiq(:,:,3)/max_q;

I can’t understand why the matrix multiplication fails. I want the code to be nice and not just to, multiply the matrix by hand…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:25:48+00:00Added an answer on May 26, 2026 at 8:25 pm

    You try to multiple a 3D array with the matrix you created which is not a proper matrix multiplication. You should unfold your image data to a 3-by-m*n matrix and multiply it with your custom matrix.

    Here is a solution for applying custom color space conversions to an RGB image. I used the matrix that you provided and compared it to the built-in YIQ transform.

    %# Define the conversion matrix
    matrix = [0.299  0.587  0.114;
              0.596 -0.274 -0.322;
              0.211 -0.523  0.312];
    
    %# Read your image here
    rgb = im2double(imread('peppers.png'));
    subplot(1,3,1), imshow(rgb)
    title('RGB')
    
    
    %# Convert using unfolding and folding
    [m n k] = size(rgb);
    
    %# Unfold the 3D array to 3-by-m*n matrix
    A = permute(rgb, [3 1 2]);
    A = reshape(A, [k m*n]);
    
    %# Apply the transform
    yiq = matrix * A;
    
    %# Ensure the bounds
    yiq(yiq > 1) = 1;
    yiq(yiq < 0) = 0;
    
    %# Fold the matrix to a 3D array
    yiq = reshape(yiq, [k m n]);
    yiq = permute(yiq, [2 3 1]);
    
    subplot(1,3,2), imshow(yiq)
    title('YIQ (with custom matrix)')
    
    
    %# Convert using the rgb2ntsc method
    yiq2 = rgb2ntsc(rgb);
    subplot(1,3,3), imshow(yiq2)
    title('YIQ (built-in)')
    

    YIQ results

    Note that k will be 3 for RGB images. See the size of the matrices after each statement. And don’t forget to convert your image to double.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using MVC2 I have an AJAX form which is posting to a bound model.
Using Java,I have to fetch multiple sets of values from an XML file to
Using MVVM. I have a DataTemplate which I am using to display an expander
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using CRM 4, I have an entity form that contains a tab with an
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
Using SolrNet for querying & faceting. I have a combination of int, tdate and
using chrome and ff so far have made a nasty glitch when using scrollTo
Using Yii, I want to delete all the rows that are not from today.
In some reason google does not have good examples of using cvCalcPGH() nor other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.