Prev: Tab-expansion freezes matlab, signal for interupting?
Next: need help about IEEE 802.16-2004 model MATLAB Simulink parameter
From: megha bhatt on 4 Jun 2010 08:50 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <09a08866-4dbd-46e6-bbc5-b902007c115b(a)e6g2000vbm.googlegroups.com>... > Just get a logical image of your ROI and get the mean of each band - > that's one way to do it > > for k = 1:64 > bandKImage = fullSpectralImage(:,:,k); > meanOfBandK(k) = mean(bandKImage(logicalMask)); > end The size of logical mask I am creating in the way I already shown is same as picture size. The number of rows and columns which I find using find function are 32005X1 it means when I extract the image from this mask, it should have 32005X32005 size where as I am getting [test=bandKImage(BW);] the size as 32005X1. Is the way I am creating mask correct? my idea was to get spectral values based on row and column indexes first and then take a mean to get a mean spectra but if I try to do so, I get memory error messages. Please suggest me something to solve this problem. Thanks.
From: megha bhatt on 4 Jun 2010 09:20 "megha bhatt" <mubhatt19(a)yahoo.co.in> wrote in message <huasqe$f3h$1(a)fred.mathworks.com>... > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <09a08866-4dbd-46e6-bbc5-b902007c115b(a)e6g2000vbm.googlegroups.com>... > > Just get a logical image of your ROI and get the mean of each band - > > that's one way to do it > > > > for k = 1:64 > > bandKImage = fullSpectralImage(:,:,k); > > meanOfBandK(k) = mean(bandKImage(logicalMask)); > > end > The size of logical mask I am creating in the way I already shown is same as picture size. The number of rows and columns which I find using find function are 32005X1 it means when I extract the image from this mask, it should have 32005X32005 size where as I am getting [test=bandKImage(BW);] the size as 32005X1. > Is the way I am creating mask correct? my idea was to get spectral values based on row and column indexes first and then take a mean to get a mean spectra but if I try to do so, I get memory error messages. > Please suggest me something to solve this problem. > Thanks. I am sorry the size can not be 32005X32005. I could extract the spectra in folloing way : for i=1:length(row) test(i,:)=squeeze(img.rad(row(i),col(i),:)); end but the speed of code is extremely slow :( please answer me how I can do the same in efficient way?? Thanks.
From: ImageAnalyst on 4 Jun 2010 11:06 On Jun 4, 8:50 am, "megha bhatt" <mubhat...(a)yahoo.co.in> wrote: > The size of logical mask I am creating in the way I already shown is same as picture size. The number of rows and columns which I find using find function are 32005X1 it means when I extract the image from this mask, it should have 32005X32005 size where as I am getting [test=bandKImage(BW);] the size as 32005X1. > Is the way I am creating mask correct? my idea was to get spectral values based on row and column indexes first and then take a mean to get a mean spectra but if I try to do so, I get memory error messages. > Please suggest me something to solve this problem. > Thanks. -------------------------------------------------------------------------------------------------------------------------------- Did I say to use find()? No, I didn't. So don't do that. Do it like I said and it will be very fast. Here's a demo for a single channel. You just have to do this for every channel in your multispectral image: % 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; % 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. fontSize = 20; % Read in standard MATLAB gray scale demo image. grayImage = imread('cameraman.tif'); subplot(2, 2, 1); imshow(grayImage, []); title('Original Grayscale Image', 'FontSize', fontSize); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. message = sprintf('Left click and hold to begin drawing.\nLift mouse button to finish'); uiwait(msgbox(message)); hFH = imfreehand(); % Create a binary image ("mask") from the ROI object. binaryImage = hFH.createMask(); % Display the freehand mask. subplot(2, 2, 2); imshow(binaryImage); title('Binary mask of the region', 'FontSize', fontSize); % Get coordinates of the boundary of the freehand drawn region. structBoundaries = bwboundaries(binaryImage); xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates. x = xy(:, 2); % Columns. y = xy(:, 1); % Rows. subplot(2, 2, 1); % Plot over original image. hold on; % Don't blow away the image. plot(x, y, 'LineWidth', 2); % Burn line into image by setting it to 255 wherever the mask is true. burnedImage = grayImage; burnedImage(binaryImage) = 255; % Display the image with the mask "burned in." subplot(2, 2, 3); imshow(burnedImage); title('New image with mask burned into image', 'FontSize', fontSize); % Mask the image and display it. % Will keep only the part of the image that's inside the mask, zero outside mask. maskedImage = grayImage; maskedImage(~binaryImage) = 0; subplot(2, 2, 4); imshow(maskedImage); title('Masked Image', 'FontSize', fontSize); % Calculate the mean meanGL = mean(maskedImage(binaryImage)); message = sprintf('Mean value within drawn area = %.3f', meanGL); msgbox(message);
From: megha bhatt on 5 Jun 2010 13:41 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <9bc1ceea-7e44-4062-aa72-a0d263ba371a(a)y4g2000yqy.googlegroups.com>... > On Jun 4, 8:50 am, "megha bhatt" <mubhat...(a)yahoo.co.in> wrote: > > The size of logical mask I am creating in the way I already shown is same as picture size. The number of rows and columns which I find using find function are 32005X1 it means when I extract the image from this mask, it should have 32005X32005 size where as I am getting [test=bandKImage(BW);] the size as 32005X1. > > Is the way I am creating mask correct? my idea was to get spectral values based on row and column indexes first and then take a mean to get a mean spectra but if I try to do so, I get memory error messages. > > Please suggest me something to solve this problem. > > Thanks. > -------------------------------------------------------------------------------------------------------------------------------- > > Did I say to use find()? No, I didn't. So don't do that. Do it like > I said and it will be very fast. > > Here's a demo for a single channel. You just have to do this for > every channel in your multispectral image: > > % 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; % 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. > fontSize = 20; > > % Read in standard MATLAB gray scale demo image. > grayImage = imread('cameraman.tif'); > subplot(2, 2, 1); > imshow(grayImage, []); > title('Original Grayscale Image', 'FontSize', fontSize); > set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. > message = sprintf('Left click and hold to begin drawing.\nLift mouse > button to finish'); > uiwait(msgbox(message)); > hFH = imfreehand(); > > % Create a binary image ("mask") from the ROI object. > binaryImage = hFH.createMask(); > % Display the freehand mask. > subplot(2, 2, 2); > imshow(binaryImage); > title('Binary mask of the region', 'FontSize', fontSize); > > % Get coordinates of the boundary of the freehand drawn region. > structBoundaries = bwboundaries(binaryImage); > xy=structBoundaries{1}; % Get n by 2 array of x,y coordinates. > x = xy(:, 2); % Columns. > y = xy(:, 1); % Rows. > subplot(2, 2, 1); % Plot over original image. > hold on; % Don't blow away the image. > plot(x, y, 'LineWidth', 2); > > % Burn line into image by setting it to 255 wherever the mask is true. > burnedImage = grayImage; > burnedImage(binaryImage) = 255; > % Display the image with the mask "burned in." > subplot(2, 2, 3); > imshow(burnedImage); > title('New image with mask burned into image', 'FontSize', fontSize); > > % Mask the image and display it. > % Will keep only the part of the image that's inside the mask, zero > outside mask. > maskedImage = grayImage; > maskedImage(~binaryImage) = 0; > subplot(2, 2, 4); > imshow(maskedImage); > title('Masked Image', 'FontSize', fontSize); > > % Calculate the mean > meanGL = mean(maskedImage(binaryImage)); > message = sprintf('Mean value within drawn area = %.3f', meanGL); > msgbox(message); > > ------------------------------------------------------------------------------------------------------------------------ Thanks a lot! now my code is perfectly doing what I wanted and also it is extremely fast. Thanks for this nice example. Regards, Megha
From: ImageAnalyst on 5 Jun 2010 15:21
On Jun 5, 1:41 pm, "megha bhatt" <mubhat...(a)yahoo.co.in> wrote: > Thanks a lot! now my code is perfectly doing what I wanted and also it is extremely fast. Thanks for this nice example. > Regards, > Megha ----------------------------------------- You're welcome. |