saving the R G B values displayed with impixelinfo in an image into a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Florian Bidaud
am 15 Aug. 2023
Bearbeitet: Florian Bidaud
am 15 Aug. 2023
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 Kommentare
DGM
am 15 Aug. 2023
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
am 15 Aug. 2023
Indeed that is probably better to use im2double. Just for information for the reader, selectedpix2/255 will give the same as selectedpix3.
Image Analyst
am 17 Aug. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!