how do i crop an image using its matrix data?
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Evan
2013년 7월 11일
편집: Evan
2013년 7월 11일
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:
outOfBounds = img >= maxBrightness;
croppedImg = img;
croppedImg(sum(outOfBounds,2) >= pctg * size(img,2),:) = [];
This, of course, if very general. You set maxBrightness 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 the sum statement entirely and just replace it with any(outOfBounds,2).
추가 답변 (1개)
Dishant Arora
2013년 7월 11일
I = imread('ImageName');
I = imcrop(I)
댓글 수: 2
Dishant Arora
2013년 7월 11일
J = (YourImage==255);
YourImage(:,all(J,1))='';
Yourimage(all(J,2),:)='';
Hope this is what you want.
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!