MATLAB: How do i crop an image using its matrix data
image processing
I have a jpeg image with the required image only in the center. i need to crop the white portion of the image i.e to obtain only the center image. how do i do this?
thanks.
Best Answer
It's a bit hard to tell what exactly needs to be done without you defining your need in a more detailed way. Do you want to only plot a portion of the data and retain the rest? Do you want to throw out any row with a saturated (255) pixel in it? Do you only want to throw out rows where a certain percentage is saturated? Etc.
Here's a generalized answer, but you'll have to tailor it too what exactly you want:
This, of course, if very general. You setmaxBrightness yourself. It could be 255 or something lower.pctg is the percentage of elements in your row exceeding max brightness that causes you to delete the row. If even a single value over the max is too many, you can remove thesum statement entirely and just replace it withany(outOfBounds,2).
I wonder what the purpose of this is, but here goes:
Image1 = imread('rice.png'); % conveniently is 256x256.
Image2 = uint8(zeros(8,8)); %Artificial image 2.
Image3 = Image1; Image3(1:8,1:8) = Image2; %change the indices 1:8 to wherever you want to put the Image2 in Image1;
You could add the bounding box, if that's what you mean, by manually adding rows and columns of black pixels around your Image2. Image2(1,:) = ones(size(Image2(1,:))); and so on for all the borders. Does this work?
Best Answer