From: Alex Jin on 16 Apr 2010 08:23 I have an image which has a grey background and the place i wanted to crop is slightly darker.. thinking of doing this: thresholdValue = 100; binaryImage = Image > thresholdValue; will show the darker part.. how would i get the bounding box of the darker region? or there are better ways to get the image cropped? Thank you very much in advance.
From: ImageAnalyst on 16 Apr 2010 08:39 Use the any() function to find the row and column limits of your region, then use imcrop() to do the actual cropping.
From: Alex Jin on 16 Apr 2010 08:58 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <664b6646-acdf-4175-a166-93e03966481b(a)r27g2000yqn.googlegroups.com>... > Use the any() function to find the row and column limits of your > region, then use imcrop() to do the actual cropping. I don really understand the any() part.. It test whether the element is a 0 or a 1.. but i don understand what to use the any() function on.. I am new on Matlab.. I hope to learn more.. thanks
From: ImageAnalyst on 16 Apr 2010 10:43 Well if you want to find the first and last rows (or columns) that have a 1 in them, don't you need to check which rows have a 1 in them? Think about it. How would you do it? If you can't figure it out then study the demo below: clc; % Read in standard MATLAB grayscale demo image. grayImage = double(imread('moon.tif')); subplot(2, 2, 1); imshow(grayImage, []); title('Original Grayscale Image'); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. binaryImage = grayImage > 100; subplot(2, 2, 2); imshow(binaryImage, []); title('Binary Image'); col1 = find(any(binaryImage, 1), 1, 'first') col2 = find(any(binaryImage, 1), 1, 'last') row1 = find(any(binaryImage, 2), 1, 'first') row2 = find(any(binaryImage, 2), 1, 'last') boxX = [col1 col2 col2 col1 col1]; boxY = [row1 row1 row2 row2 row1]; hold on plot(boxX, boxY, 'r-', 'LineWidth', 2); croppedImage1 = imcrop(grayImage, [col1, row1, (col2-col1+1) (row2- row1+1)]); subplot(2, 2, 3); imshow(croppedImage1, []); title('Cropped Gray Image'); croppedImage2 = imcrop(binaryImage, [col1, row1, (col2-col1+1) (row2- row1+1)]); subplot(2, 2, 4); imshow(croppedImage2, []); title('Cropped Binary Image');
From: ImageAnalyst on 20 Apr 2010 14:53
Cropping is not your problem. You aren't even close to segmenting your region of interest. That is too complicated an image to do simple thresholding on. You need to figure out how to get that first, before you start thinking about cropping. |