saving the R G B values displayed with impixelinfo in an image into a matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Florian Bidaud
il 15 Ago 2023
Modificato: Florian Bidaud
il 15 Ago 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 Commenti
DGM
il 15 Ago 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
il 15 Ago 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
il 17 Ago 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 Commenti
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!