MATLAB Image Processing _ directly operate on the pixel for color conversion, matlab Image Processing

Source: Internet
Author: User

MATLAB Image Processing _ directly operate on the pixel for color conversion, matlab Image Processing

Requirement

Directly operate the pixels of the RGB image and perform color-related operations.

To master this, you must be familiar with matrix operations in MATLAB, especially the operations of the entire row and the entire column.

For example:

J = [1 2 3; 4 5 6; 7 8 9]; -- a matrix of three rows and three columns is defined here.

J [:, 1] = 0; -- directly operates the 1st columns of each row in the J matrix. At this time, J = [0 2 3; 0 5 6; 0 8 9]

Other operations, such as the row operation usage, are not described in detail.

Next we will perform a direct operation on an image and change the red part to blue.

The Code is as follows:

% BY   SCOTT                                                                                                                                              % red2blue% change red to blueclear all;clc;rgb = imread('red2blue.png');figure;imshow(rgb);R=rgb(:,:,1); %redG=rgb(:,:,2); %greenB=rgb(:,:,3); %blue[x,y,z]=size(rgb);for i=1:x    for j=1:y        if( (R(i,j) >= 180) && (R(i,j) <=255) && (G(i,j) <50) && (B(i,j) <50) )            R(i,j) = 0;            G(i,j) = 162;            B(i,j) = 232;        end    endend% in this way% blue(:,:,1)=R(:,:);% blue(:,:,2)=G(:,:);% blue(:,:,3)=B(:,:);% another wayfor i=1:x    for j=1:y        blue(i,j,1) = R(i,j);        blue(i,j,2) = G(i,j);        blue(i,j,3) = B(i,j);    endendfigure;imshow(blue);

Running result:

Before conversion:


After conversion:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.