Color image reading and writing experiment of MATLAB operation

Source: Internet
Author: User

Define a function Subsamp, enter a color image file name, output and display the color of half the size

Image (original, flip horizontally, flip vertically, center area red). You must use the control statement to successfully invoke the command Window!

Because color images are 3-dimensional, black-and-white images are 2-dimensional. If we're still using it when we halve the size of the image

>> f=imread (' e:\1.png ');>> f=f (1:2:end,1:2:end);>> imshow (f);

We'll find out. Three gray images arranged in a single side

So you can add 1 dimensions to the back.

The entire code is as follows

function [Img1,img2,img3,img4]=subsamp (filename); img1=imread (filename); i=1:4 Figure    switch I case        1            img1=img1 (1:2:end,1:2:end,:);% makes the image size halved            imshow (IMG1);        Case 2            img2=img1 (end:-1:1,:,:);% causes the image to flip horizontally            imshow (IMG2);        Case 3            img3=img1 (:, end:-1:1,:);% causes the image to flip vertically            imshow (IMG3);        Case 4            100*100 the image Center area red            [M,n,t]=size (IMG1);            IMG4=IMG1;            IMG4 (m/2-50:m/2+50,n/2-50:n/2+50,1) =255;            IMG4 (m/2-50:m/2+50,n/2-50:n/2+50,2) =0;            IMG4 (m/2-50:m/2+50,n/2-50:n/2+50,3) =0;            Imshow (IMG4);    EndEnd            

Run results

Color image reading and writing experiment of MATLAB operation

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.