Effacer les filtres
Effacer les filtres

image axes modification/ pixel extension

1 vue (au cours des 30 derniers jours)
Amit Ifrach
Amit Ifrach le 25 Déc 2022
Commenté : Image Analyst le 25 Déc 2022
Hello guys,
I wrote a code that imports PNG image (microscopre source, 30 nm pixel size) and overlays certain spot locations (mathematically, no pixels of course) on it which imported from a csv file.
The PNG is pixelated, so when I want to overlay the CSV points correctly, I must divide the CSV's data by the pixel size (30).
My problem with that is that all calculation and axis of later created images "talk" with the pixelated axes and not actual size (nm).
I would like somehow to 'enlrage'/'extend' the PNG file times 30 or some other solution that will conver the pixelated data to mathematical data (if I managed to clearify myself).
I saw somewhere that in the image tool box exists such a tool that make [1 2 3] to [111 222 333] if requested.
Do you think it will solve it? have any other idea?
Thanks,
Amit.

Réponses (3)

Karim
Karim le 25 Déc 2022
Modifié(e) : Karim le 25 Déc 2022
You could use repelem to do this. Say that you have a matrix with 5 rows and 8 columns:
Idx = reshape(1:5*8,5,8)
Idx = 5×8
1 6 11 16 21 26 31 36 2 7 12 17 22 27 32 37 3 8 13 18 23 28 33 38 4 9 14 19 24 29 34 39 5 10 15 20 25 30 35 40
And we want to repeat the indexes, to augment the data:
Idx_aug = repelem( Idx, 3, 3 )
Idx_aug = 15×24
1 1 1 6 6 6 11 11 11 16 16 16 21 21 21 26 26 26 31 31 31 36 36 36 1 1 1 6 6 6 11 11 11 16 16 16 21 21 21 26 26 26 31 31 31 36 36 36 1 1 1 6 6 6 11 11 11 16 16 16 21 21 21 26 26 26 31 31 31 36 36 36 2 2 2 7 7 7 12 12 12 17 17 17 22 22 22 27 27 27 32 32 32 37 37 37 2 2 2 7 7 7 12 12 12 17 17 17 22 22 22 27 27 27 32 32 32 37 37 37 2 2 2 7 7 7 12 12 12 17 17 17 22 22 22 27 27 27 32 32 32 37 37 37 3 3 3 8 8 8 13 13 13 18 18 18 23 23 23 28 28 28 33 33 33 38 38 38 3 3 3 8 8 8 13 13 13 18 18 18 23 23 23 28 28 28 33 33 33 38 38 38 3 3 3 8 8 8 13 13 13 18 18 18 23 23 23 28 28 28 33 33 33 38 38 38 4 4 4 9 9 9 14 14 14 19 19 19 24 24 24 29 29 29 34 34 34 39 39 39

Image Analyst
Image Analyst le 25 Déc 2022
True, all the image processing functions deal with pixels. If your CSV data is in nm, then you must divide by the number of nm per pixel AND round the values if you want the coordinates in pixels. But it depends on what you want to do with the CSV data. If you want to plot it in the overlay, you don't need to round the values. If you want to get the image value at the CSV location, you will need to round the value to the nearest pixel.
You can do what you ask with repelem but I don't recommend it. It will just enlarge your image unnecessarily. Doing that will give you roughly a spatial calibration factor of 1 nm per pixel, but you may still have a quantization problem if your nm per pixel is not an integer to begin with (for example 30.5 instead of 30).
The usual way we handle that is to do the computations, like with regionprops, in pixels. Then when it comes time to get real world values out of it we multiply the linear distances by the number of nm per pixel and the area metrics by the number of nm per pixel squared. For example
props = regionprops(mask, 'MajorAxisLength', 'Area');
allLengthsInPixels = [props.MajorAxisLength];
allAreasInPixels = [props.Area];
nmPerPixel = 30; % Define spatial calibration factor.
allLengthsInNm = allLengthsInPixels * nmPerPixel;
allAreasInSquareNm = allAreasInPixels * nmPerPixel ^ 2;
  1 commentaire
Image Analyst
Image Analyst le 25 Déc 2022
Regarding your Answer, the first input to regionprops is your binary image. The image you segmented from the gray scale image to produce, basically, foreground and background in a binary image.
What exactly did you mean when you said "all calculation and axis of later created images "talk" with the pixelated axes"? I assumed you meant the whole collection of functions in the Image Processing Toolbox, such as regionprops, bwmorph, bwarea, etc.
You can certainly divide the coordinates in your CSV file by 30 to get pixel coordinates, and you're doing that, but I don't know what you mean by the subsequent calculations you want to do. You can certainly do voronoi on the original CSV values. I don't know what "ROI them properlym" means. Are you getting a labeled image from voronoi and then using regionprops on it? If you want the area of each region, you could use polyarea instead of reginprops to get area in original units instead of pixel units.

Connectez-vous pour commenter.


Amit Ifrach
Amit Ifrach le 25 Déc 2022
Modifié(e) : Amit Ifrach le 25 Déc 2022
Hi Karim and Image Analyst, thanks!
I tried to read about the mask option on the regionprops page but it seems non-existent. maybe I'll tell you why I need the PNG (which I dont really care about), to make thing a little bit more clear.
My main interest is to do voronoi analysis of the CSV's points. I need to know what is the boundary of these points so I can ROI them properlym which is what the PNG is for (orientation only). ultimately I just want the image and CSV points to be at the exact same location and in nm axis.
For example:
If u can see, this is a PNG of ThunderStorm (TS) analysis of bright points (originates from tiff of course). the red dots are the TS output from ImageJ and I overlayed the green dots (hard to see but they exist if u look carefully). I only need the PNG to see where the blood cell footprint exists.
I just didn't understand if the answer of IA is the correct for me. I don't even understand how it should work in my code tbh :|.
Thank you very very much!
Amit.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by