compare pixel values to each other? Is ther afunction in Matlab that can analyze the composition of an image as a function of distance?
Mostra commenti meno recenti
I am interested in looking at how the image changes over a distance within the image, any recommendations?
Thanks!
8 Commenti
Jon
il 16 Dic 2022
This is a MATLAB forum, looks like you are looking for a Python forum
Neo
il 16 Dic 2022
Walter Roberson
il 16 Dic 2022
Modificato: Walter Roberson
il 16 Dic 2022
What do you mean by "composition of an image" in this situation ? What is "distance" in this situation ?
You can calculate distances between positions in an image without too much difficulty if distances are linear.
WIth the Computer Vision toolbox, you can correct for image distortion before calculating distances with a little more work.
But if you have uncorrected perspective then figuring out distances can be tricky. Is the brick wall curving away, allowing you to use the mortor for distance calculations, or is it just an oddly shaped object that happens to be squished-looking toward the edges?
Neo
il 21 Dic 2022
Spostato: Walter Roberson
il 21 Dic 2022
Walter Roberson
il 21 Dic 2022
Spostato: Rena Berman
il 22 Dic 2022
And you want to know how the size and area and density of the one cell changes over distance from ... something??
Neo
il 21 Dic 2022
Spostato: Rena Berman
il 22 Dic 2022
Image Analyst
il 22 Dic 2022
If you have any more questions, then attach your image and code to read it in with the paperclip icon after you read this:
And somehow indicate, in a separate image, the things in the image you'd like to use in computations.
Risposta accettata
Più risposte (1)
Walter Roberson
il 21 Dic 2022
1 voto
The answer to your question is NO, there is no MATLAB function to analyze the composition of an image as a function of distance.
14 Commenti
Neo
il 21 Dic 2022
Walter Roberson
il 21 Dic 2022
First you need to figure out where the cell boundaries are. Then you need to "label" the image, producing an array the same size in which each location gives an identifier about which of the cells the pixel belongs to (0 if not part of any cell.) Then you process the grayscale image, converting the intensity into a pixel weight.Then you call regionprops passing in the label image and the weight image, using the syntax that regionprops summarizes as
Ask for the properties Area, Centroid, MeanIntensity
The MeanIntensity will be the (average) density, provided that you supplied a valid weight image.
The conversion from intensity to pixel weight might take a bit of work. Different colors might imply different material compositions. Darker portions in the centre of a cell might relate to the cell nucleus, which would not just be thicker but denser than some of the other parts of the cell. Perhaps you are using a polarized light source, so you might be looking at texture information to get clues about the local density. Perhaps the shape of the nucleus might give information about the kind of cell it is and so influence the interpretation of the intensity conversion to local density.
Neo
il 28 Dic 2022
Walter Roberson
il 28 Dic 2022
If you know the RGB for an isolated pixel, can you figure out its material composition and so the implied density? Or do you need to see the RGB in the context of surrounding pixels in order to figure out the material composition?
For example, is this particular pixel this particular shade of red-ish because it is a dye-injected rubber ball, or because it is dye-injected plastic? Knowing only one isolated pixel might not be enough to say, but seeing a small number of adjacent pixels might potentially give enough information to allow you decide, hypothetically.
You might have to correct for uneven illumination before you analyze color to determine composition.
You might end up using a strategy such as quantizing Hue to guess about composition.
Neo
il 28 Dic 2022
Suppose you have a pixel that is (say) [240 27 93] and you have another pixel that is [200 23 78]
plot(1:10, .1*ones(1,10), 'color', [240 27 93]/255);
hold on
plot(1:10, .11*ones(1,10), 'color', [200 23 78]/255);
hold off
ylim([.05 .115])
Are they the same material or different material? If you look at them carefully, you can see that they do not look exactly the same, so you might need to assign them different materials. Rubber versus plastic for example. Different parts of a cell structure maybe.
But are they really different materials? Are are they the same material with slightly different lighting conditions? Is one of them in a little more shadow than the other? Is one of them the same material than the other, but the system is backlit and a part is slightly thicker and so cuts off more backlight? Or has the experiment been set up carefully so that the lighting can be treated as being uniform parallel rays over the entire field so that any variation in color is not due to differences in shadow or thickness ?
If you cannot reasonably model as uniform parallel rays, then you need to be considering doing correction for illumination.
im2uint8(double(img) ./ double(max(img, 3)))
which divides each location by the maximum component at that location. This treats each location as if it is potentially uniform material but subject to different lighting levels -- as opposed to a model where a pixel that is (say) 3/4 of each component of a different pixel, is different because it is inherently a different material. If you need to differentiate pixels in part by brightness instead of just by hue, then illumination correction becomes more difficult.
Walter Roberson
il 29 Dic 2022
There is typically no way to look at the pixels of an image and inherently read off density directly from them. Not necessarily impossible -- but it would need a setup such as a thin layer of liquid at each location and a uniform illumination from the top, and somehow the pixel color was tied to the density at the point (for the uniform volume there.) Maybe something like monochrome laser being attenuated differently for different densities. It can happen -- but it is rather unusual.
Instead you typically need to classify a given RGB value somehow as belonging to a given class of materials, and then look in a data table to find out what the density is associated with that class of material. Dull orange is "orange juice with lots of pulp", bright orange is "orange juice with a little pulp", black-ish is Coca-Cola ™ , this shade of red is Mountain Dew ™ and so on, and you have stored information about density of each of those kinds of materials.
Neo
il 29 Dic 2022
Walter Roberson
il 29 Dic 2022
Yes. It is quite uncommon to be able to read out density of a pixel directly. It is more common that you need to map pixel color or texture information to material and pull out the known density for the kind of material.
Once you have created an array the same size as the image, but containing the per-pixel density associated with the material, you can pass that pixel density as the second parameter to regionprops, with the first parameter being the label image. Ask for mean intensity in order to find the density of the region (as opposed to the density of a point.) This will be equivalent to summing the per-point density information over the region and dividing by the number of pixels in the region. Then you can compare region densities between regions.
Image Analyst
il 29 Dic 2022
Why don't we race to the solution and you just show us your image? If you have any more questions, then attach with the paperclip icon, or insert your image with the frame icon, after you read this:
In the meantime, to illustrate what Walter said, assume this is your image:

So we have a white background (countertop), red strawberries, and turquoise stone nuggets. Now all you have is this image. Of course you can do color segmentation and find the mean RGB values of the strawberries and turquoise, but how are you going to know, from only those values, in the range 0-255, that the density of turquoise is 2.7 grams/cc and the density of strawberries is 0.59 grams/cc? Answer: You can't. That is something you'd need to obtain in some other way than analyzing an image.
Neo
il 29 Dic 2022
Image Analyst
il 29 Dic 2022
Modificato: Image Analyst
il 29 Dic 2022
originalImage must be a gray scale image. Yours is not. You can do
originalImage = originalImage(:, :, 2); % Take green channel
It looks like you have a fluorescence image so you would not do a background division like usual. For radiography (x-rays) and fluorescence you do background subtraction. For most other situations you do background division. You'd do a background subtraction. But your background looks pretty black and uniform so that is probably not even necessary.
Just a slight correction to what @Walter Roberson said about how I do background correction. I don't divide by the max of any color channel. I divide by a smoothed version of each color channel individually. This is because the lens shading and transverse chromatic aberration of the lens might be wavelength dependent. In other words, it might taper off on the sides of the image more for one color channel than another so I need to correct for each color channel independently. This could be a whole hour long discusson but I won't go into that here. I'll just attach the image of an actual white background image taken from one of our light booths (a small JPG version -- less than 5 MB so I can upload it) and script to take vertical and horizontal profiles so you can see how the shading varies by color channel.

Note the profiles are still very noisy. This is most likely not due to illumination non-uniformities because light wouldn't vary that much on a small scale. The non-uniformities are most likely due to variations in the white substrate itself, and slightly due to optical noise remaining in the image. The overall differences between the different color channels is most likely due to chromatic aberration of the lens. The lens shading is different for optical wavelengths in the red, green, and blue regions of the spectrum. This will affect both the overall intensity level as well as the amount of shading (darkening) across the image.
The spectrum of the white substrate is almost perfectly flat - I checked with a spectrophotometer. The light is "white" light LED so it's possible there could be a difference in the overall levels of the red, green, and blue light due to the particular way the spectrum of the light interacted with the spectral responsivities of the imaging sensor. For example the light is a "warm white" so there would be more red light being emitted. Note the top and right side of the image is more neutral than the bottom or left edge of the image.
If you want, I can upload my background correction, color correction, and color calibration seminar.
Neo
il 29 Dic 2022
Image Analyst
il 29 Dic 2022
See attached seminar on background correction, color correction, and color calibration. I've just updated some slides from what I've posted in the past years..
Categorie
Scopri di più su Blue in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
