From: Rudra on 7 Apr 2010 02:27 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <f4af3dae-0c89-4cbe-a2e3-0ef1abe06033(a)o30g2000yqb.googlegroups.com>... > Rudra: > Strange, it seems to work for me. > You can type "doc colon" in the command window to get an explanation, > but basically this is the standard MATLAB concept where you have > startingValue:incrementValue:endingValue. You'd better learn this > soon if you want to progress in your MATLAB programming. "end" is > just a shortcut to getting the the last index value of the array so > you don't actually have to find it out yourself with the size() > function - it's just already there for you to use. > > You didn't post your code so no one can figure out where you messed > up. So I made up some demo code for you to illustrate the concept. > Note that if you have color images, you'll have to handle the third > dimension - this demo is only for 2D gray scale images. > > Be sure to join any lines split into two by the newsreader. > > % Change the current folder to the folder of this m-file. > % (The line of code below is from Brett Shoelson of The Mathworks.) > if(~isdeployed) > cd(fileparts(which(mfilename))); > end > clc; % Clear command window. > clear all; % Delete all variables. > close all; % Close all figure windows except those created by imtool. > imtool close all; % Close all figure windows created by imtool. > workspace; % Make sure the workspace panel is showing. > > % Read in standard MATLAB gray scale demo image. > grayImage = imread('cameraman.tif'); > subplot(2, 2, 1); > imshow(grayImage, []); > title('Original Grayscale Image', 'FontSize', 20); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > [rows columns numberOfColorBands] = size(grayImage); > message = sprintf('For the original image:\n# Rows = %d\n# Columns = %d > \n# Color Bands = %d', rows, columns, numberOfColorBands); > uiwait(msgbox(message)); > > % Sub-sample the image. > oddSubSampledImage = grayImage(1:2:end, 1:2:end); > subplot(2, 2, 3); > imshow(oddSubSampledImage, []); > title('Odd Sampled Image', 'FontSize', 20); > [rowsOdd columnsOdd numberOfColorBandsOdd] = size(oddSubSampledImage); > message = sprintf('For the odd image:\n# Rows = %d\n# Columns = %d\n# > Color Bands = %d', rowsOdd, columnsOdd, numberOfColorBandsOdd); > uiwait(msgbox(message)); > > evenSubSampledImage = grayImage(2:2:end, 2:2:end); > subplot(2, 2, 4); > imshow(evenSubSampledImage, []); > title('Even Sampled Image', 'FontSize', 20); > [rowsEven columnsEven numberOfColorBandsEven] = > size(evenSubSampledImage); > message = sprintf('For the even image:\n# Rows = %d\n# Columns = %d\n# > Color Bands = %d', rowsEven, columnsEven, numberOfColorBandsEven); > uiwait(msgbox(message)); _________________________________________________________________ Thank you for all the replies: To tell you what code I'm working on I'll paste the code below: X = imread ('filename.png'); for j=1:400 for i=1:268 r=rem(i,2); if r==0 a=X(j,i); else b=X(j,i); end end end I wrote this loop to put values of alternate pixels in the matrices a and b. But the result is not what I intended for. The variables a and b behave as true variables that is when the loop is executed every time the value of a and b changes to the new pixel value and at last the last pixel value is only in it. I want to define a and b as matrixes, so that whenever the loop is executed the values of every iteration is stored one below the other so that I can extract any value by just typing a(3) just to read the third value in the matrix. Can I do that plz help. Thank You
From: ImageAnalyst on 7 Apr 2010 06:20 Either use my code and refer to the pixel using row,col coordinates, or look at the subs2ind() and ind2subs() functions if you want linear indexing (which I think you'll find less intuitive).
First
|
Prev
|
Pages: 1 2 Prev: ellipse or ellipsoid-fit for x,y,z data Next: Delaunay Trianggle selection |