From: Rudra on 6 Apr 2010 05:12 Hi, I want to read all the pixel values at alternate locations of a given image to alternate matrices, is it possible in matlab. I have read the image using 'imread' which gives all the pixel values in a matrix X and after that I want all the values at even location in the matrix X goes to a and values corresponding to odd locations go to matrix b. so that i have all the alternate values in a and b respectively. please help if you can... thankx...
From: ImageAnalyst on 6 Apr 2010 06:17 Try this: evenImage = originalImage(2:2:end, 2:2:end); oddImage = originalImage(1:2:end, 1:2:end); Try to avoid short, non-descriptive variable names like X, a, and b - it makes your code hard to maintain later if you have lots of variables.
From: Rudra on 6 Apr 2010 07:25 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <cba6dd19-6944-4750-a3f8-33bd9fcbe4bb(a)v20g2000yqv.googlegroups.com>... > Try this: > evenImage = originalImage(2:2:end, 2:2:end); > oddImage = originalImage(1:2:end, 1:2:end); > > Try to avoid short, non-descriptive variable names like X, a, and b - > it makes your code hard to maintain later if you have lots of > variables. Can you please illustrate what exactly is meant by " 2:2:end, 2:2:end" because it is not reading the pixels properly it is leaving some of the values. I just want to know what does this numbers mean as they are placed after every : what do they represent. are these row or column numbers??!!
From: Sean on 6 Apr 2010 08:01 "Rudra " <rudraprasadguha(a)hotmail.com> wrote in message <hpf5mi$g3m$1(a)fred.mathworks.com>... > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <cba6dd19-6944-4750-a3f8-33bd9fcbe4bb(a)v20g2000yqv.googlegroups.com>... > > Try this: > > evenImage = originalImage(2:2:end, 2:2:end); > > oddImage = originalImage(1:2:end, 1:2:end); > > > > Try to avoid short, non-descriptive variable names like X, a, and b - > > it makes your code hard to maintain later if you have lots of > > variables. > > > Can you please illustrate what exactly is meant by " 2:2:end, 2:2:end" > because it is not reading the pixels properly it is leaving some of the values. > I just want to know what does this numbers mean as they are placed after every : what do they represent. are these row or column numbers??!! evenImage = originalImage(2:2:end, 2:2:end); start:stride_length:end i.e. start at pixel 2, select every 2nd pixel, and end at the last pixel. Thus selecting even pixels since the start was at 2. This done for both dimensions. oddImage = originalImage(1:2:end, 1:2:end);
From: ImageAnalyst on 6 Apr 2010 08:01 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));
|
Next
|
Last
Pages: 1 2 Prev: ellipse or ellipsoid-fit for x,y,z data Next: Delaunay Trianggle selection |