About imwrite
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone I have a trouble about imwrite I have the code:
sav=imagesc(ycbcr2rgb(getsnapshot(handles.objVideo))); imwrite(sav,'im.bmp')
In a button in my gui, I want to save a image taken by the webcam with this command but the image saved just show me one pixel, what could be wrong? thanks a lot!
댓글 수: 0
답변 (1개)
Walter Roberson
2011년 6월 5일
imagesc() returns the handle to the image object. You are then writing that handle as if it were the image itself.
Extracting the data from the handle by using get(sav,'CData') will not work: imagesc stores the original data (as returned by ycrcb2rgb()) and does its coloring tricks by setting the image object to use colormap interpolation.
In order to save the scaled image, you either need to getframe() the scaled image and save that, or you need to do the scaling yourself. If you do the scaling yourself, you do not need the imagesc() step.
To scale the image yourself, subtract the minimum value of the image from the entire image, and then divide the result by the range of values. You will now have an array that is in the range 0 to 1. Multiply by (the size of your colormap minus one) and uint8() or uint16() the result. ind2rgb() that to get the color version. Scale to uint8 or uint16 and imwrite() the result.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!