フィルターのクリア

Image Processing along diagonal. I am a student and beginning learner of matlab, I have study some code and do not understand the meaning also the syntax of the code(the second for loop), can anybody help me? Thank you.

3 ビュー (過去 30 日間)
I = imread('lenna.tiff'); % read the image to variable I
[x y z]=size(I); % read image size to variable x, y, z
R=zeros(x,y,z); % initialize the result matrix
% copy the original block of data
for n = 1:x
R(n,1:n,:)=I(n,1:n,:);
end
% copy the inverted block of data
for n = 1:x
n
R(1:n,n,:)=I(n,1:n,:);
end
R=uint8(R); % convert it to unsiged integer
imshow(R); % display the image

回答 (1 件)

Image Analyst
Image Analyst 2012 年 11 月 26 日
That is ridiculous code - wasteful and repetitive. I recommend that you run fast and far away from that code and not use it. And whoever wrote it needs to take a refresher course in MATLAB programming. Instead you should look at the examples in the help documentation or check out my File Exchange.
  2 件のコメント
Trevor
Trevor 2012 年 11 月 28 日
編集済み: Trevor 2012 年 11 月 28 日
The code were given by the teaching associate in the university. He gave this sample for us to self learning and wants us to do a Kaleidoscope. I still haven't got any idea >_<, do you know any websites have matlab sample code about kaleidoscope that can give me a reference. I can't find any. <http://3.bp.blogspot.com/-dXAgV1Rea_M/T2o2nhrd2fI/AAAAAAAAAC8/p3uWgA2w-Kc/s1600/kaleidoscope-view.jpg>Thanks.
Image Analyst
Image Analyst 2012 年 11 月 28 日
Well I guess it does do that. Perhaps if we rename some variables and put in some comments it will help you understand.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
I = imread('peppers.png'); % read the image to variable I
[Rows columns numberOfColorChannels]=size(I); % read image size to variable x, y, z
% Crop to a square
I = I(1:Rows, 1:Rows, :); % Assumes x < y.
[Rows columns numberOfColorChannels]=size(I); % Get new square dimensions.
R=zeros(Rows,columns,numberOfColorChannels); % initialize the result matrix
subplot(2, 2, 1);
imshow(I);
title('Original Image', 'FontSize', fontSize);
% Copy a triangle from the original image.
for n = 1:Rows
R(n,1:n,:)=I(n,1:n,:);
end
subplot(2, 2, 2);
imshow(uint8(R));
title('Initial half of the R Image', 'FontSize', fontSize);
% Paste the triangle into the other triangle.
for n = 1:Rows
n
R(1:n,n,:)=I(n,1:n,:);
end
R=uint8(R); % convert it to unsiged integer
subplot(2, 2, 3);
imshow(R);
title('Final R Image', 'FontSize', fontSize);
% Go all the way around
R360 = [R imrotate(R, 270); imrotate(R, 90) imrotate(R, 180) ];
subplot(2, 2, 4);
imshow(R360);
title('R360 Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeExplore and Edit Images with Image Viewer App についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by