saving the R G B values displayed with impixelinfo in an image into a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi. How can I save the R G B values displayed with impixelinfo in an image into a matrix? (see red box)
Here is a demo image:
h = imshow("hestain.png");
hp = impixelinfo;
댓글 수: 0
답변 (2개)
Florian Bidaud
2023년 8월 15일
편집: Florian Bidaud
2023년 8월 15일
Everything is already stored in h, you can retrieve the values with h.CData(pixel_x, pixel_y, :). Be careful the values are unit8, if you want double, you need to convert them with double() function
댓글 수: 2
DGM
2023년 8월 15일
You are correct. For arithmetic operations, being in uint8 will often cause problems by itself.
Unless the user is cautious and aware of how the interpretation of image data scaling is dependent on numeric class, I suggest that it's safer to use im2double() to make sure the outputs are scaled appropriately for their class. For example, let's say you used some method to get the colors associated with a handful of pixels:
inpict = imread('peppers.png'); % a uint8 image
pixidx = [156 54684 3158 5648 3546]; % some indices
allpix = reshape(inpict,[],3);
selectedpix1 = allpix(pixidx,:) % the pixels as a Mx3 color table
selectedpix2 = double(selectedpix1) % using double()
selectedpix3 = im2double(selectedpix1) % using im2double()
Most MATLAB image tools that depend on data scale (e.g. imshow()/imwrite()) will handle case 1 or 3. Most MATLAB tools which handle color tables (e.g. rgb2ind()/ind2rgb()/imshow()/imwrite()/colormap()) will only correctly handle case 3. With case 2, those functions will either interpret the above colors as all white, or they will simply return an error.
Florian Bidaud
2023년 8월 15일
Indeed that is probably better to use im2double. Just for information for the reader, selectedpix2/255 will give the same as selectedpix3.
Image Analyst
2023년 8월 17일
Use imread to read it into an array before you display it. Then you'll have all the RGB values. It's much easier to do it this way than
rgbImage = imread("hestain.png");
imshow(rgbImage);
axis('on', 'image');
hp = impixelinfo;
If you want to mouse around and have it automatically save the RGB and (x,y) values in the status bar, I don't think you can do that. However you can call imfreehand to have the user draw some curve in the image, and then use the curve coordinates to extract the RG value, then you can write them to disk.
I'm attaching some freehand drawing demos.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!