필터 지우기
필터 지우기

How to get the original rgb image from hsv image?

조회 수: 1 (최근 30일)
Kumar Arindam Singh
Kumar Arindam Singh 2017년 4월 9일
댓글: Image Analyst 2017년 4월 9일
OK, so I have this image(in HSV) which i have got after cropping:
Now,I want to implement the same dimension cropping(i.e. the image width and height should be same as the above image) to my original(uncropped)rgb image,which is:
I used the following code
img1=imread('2.jpg');%this is the original rgb image
[y1,x1] = find(img1);
xmin1 = min(x1(:));
ymin1 = min(y1(:));
xmax1= max(x1(:));
ymax1 = max(y1(:));
width1=xmax1-xmin1+1;
height1=ymax1-ymin1+1;
img2=imread('cropbin1.jpg');%this is the HSV image
[y2,x2] = find(img2);
xmin2 = min(x2(:));
ymin2 = min(y2(:));
xmax2= max(x2(:));
ymax2 = max(y2(:));
width2=xmax2-xmin2+1;
height2=ymax1-ymin2+1;
w3=(width1-width2)/2;
h3=(height1-height2)/2;
out = imcrop(img1,[w3 h3 width2 height2]);
figure,imshow(out);
But, to my horror, the output is showing no image.
Please help.
I would like my original image to be like:
Please suggest any other way by which I can change the HSV image to a rgb image. Thanxxx.......
  댓글 수: 1
Image Analyst
Image Analyst 2017년 4월 9일
There are so many things wrong with that code, that it's just faster to give you whole new code than to explain it to you. In the meantime, I fixed your formatting but for the future, please read this: http://www.mathworks.com/matlabcentral/answers/13205#answer_18099

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2017년 4월 9일
See attached solution.
  댓글 수: 2
Kumar Arindam Singh
Kumar Arindam Singh 2017년 4월 9일
instead of find(), i used size() and the code worked for all the test images.... i will definitely check your asnwer...thank u
Image Analyst
Image Analyst 2017년 4월 9일
Not it won't. Just look at it:
xmin1 = min(x1(:));
well x1 is the number of columns multiplied by the number of color channels (3). Why? Just read http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/ So x1 is 12,960, NOT the number of columns in the image. It's not even an array, so doing this: x1(:) will not do what you thought it did. Lots more problems after that.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by