starting at x, y position of imagea region growing with pixel intensity values between 800 and 1300 in matlab

Here's some sample code in MATLAB that should do the trick. This assumes that your image is a grayscale image, and that you are looking to grow the region from the starting point in a "4-connected" manner (i.e. adjacent pixels above, below, left, and right of the current pixel are included in the region).

main.m
% Load in the image
img = imread('myImage.jpg')

% Define the starting point
startX = 100;
startY = 200;

% Set intensity thresholds
minIntensity = 800;
maxIntensity = 1300;

% Create a binary mask that will contain our region
mask = zeros(size(img,1), size(img,2));

% Set the starting pixel value to 1 to begin region growing
mask(startY, startX) = 1;

% Loop through the image, adding adjacent pixels to the region while
% their intensity values are within the threshold range
while true
    % Create a temporary mask to hold any new pixels added during this iteration
    newMask = mask;
    
    % Loop through the current mask, checking for adjacent pixels to add
    for i = 1:size(img,1)
        for j = 1:size(img,2)
            % If the pixel is already in the region, check its neighbors
            if mask(i,j) == 1 
                % Check the pixel above
                if i > 1 && img(i-1,j) >= minIntensity && img(i-1,j) <= maxIntensity && mask(i-1, j) == 0
                    newMask(i-1, j) = 1;
                end
                
                % Check the pixel below
                if i < size(img,1) && img(i+1,j) >= minIntensity && img(i+1,j) <= maxIntensity && mask(i+1, j) == 0
                    newMask(i+1, j) = 1;
                end
                
                % Check the pixel to the left
                if j > 1 && img(i,j-1) >= minIntensity && img(i,j-1) <= maxIntensity && mask(i, j-1) == 0
                    newMask(i, j-1) = 1;
                end
                
                % Check the pixel to the right
                if j < size(img,2) && img(i,j+1) >= minIntensity && img(i,j+1) <= maxIntensity && mask(i, j+1) == 0
                    newMask(i, j+1) = 1;
                end
            end
        end
    end
    
    % If the new mask is the same as the old mask, we're done growing the region
    if isequal(mask,newMask)
        break;
    else
        % Otherwise, update the mask and continue growing the region
        mask = newMask;
    end
end

% Finally, show the resulting region
imshow(mask)

2074 chars
64 lines

gistlibby LogSnag