Scan the image until the first and last points I set
Mostrar comentarios más antiguos
Hi Matlab community.
I need your valuable help on this.
Please see attached image. I annotate the starting and end point of scanning. What I want is to scan the image starting from top (where the first black pixel begins) and stop where the first gray-white pixel of the ruler of the image that lies vertically at the right edge of the image.
The same process will be repeated from the bottom of the image scanning until the first gray-white pixel of the vertical ruler that lies at the right end side of the image. The inbetween part where the imaging window lies, will be segmented, defined somehow or separated by the rest of the image, means that anything else shall be masked.
Continuing scanning from right to left after imaging window finishes, black pixels again start, so the segmentation, differentiation shall be stopped and all other details like letters, colorbars, logos, whatever shall be masked.
The only visible part of the image should be the rectangular gray imaging window. But not at the size as you see it since the actual size of the imaging window is bigger. It starts from the first gray dash of the ruler until the last gray dash close to the bottom, even if at this place the imaging window is pure black.
Am I understood? Please, ask, whatever you don't understand.
Hope to have a and solving solution, soon enough.
Thanks for everything and also the time you spent to read this.
21 comentarios
Stelios Fanourakis
el 25 de En. de 2019
Jan
el 25 de En. de 2019
I do not understand the question. Please explain, what the input is: A grey-scale image stored in a matrix? Or does the white border belong to the image and it is stored as RGB array? Which part of the posted image do you want? Please mark it manually to clarify this. Are the yello lines a hint already? "where the first black pixel begins" and "It starts from the first gray dash of the ruler until the last gray dash close to the bottom" is not clear enough.
"The size of the square (imaging window) should be the dimensions of the depth and not only what is visible" is not clear to me also. What exactly is "the depth"? The height or the width?
Yes, the language is very confusing. As far as I understand, you don't want to do any segmentation (which has a precise meaning in image processing) or scanning. All you want to do is crop the image.
In terms of height, my understanding is what you call depth (images don't have depth) are the pixels between the first and last tick mark of the ruler. So you want to crop the image height between these two tick marks.
In terms of width, I'm not sure what you want. The left and right white border is trivially removed. But after that, I'm not sure. Should the width be restricted to the inner rectangle or something else?
By the way, since the image appears to be a screen capture of an actual image displayed in some sort of software, don't you have access to that actual original image which would avoid you having to remove all that UI stuff?
Stelios Fanourakis
el 25 de En. de 2019
Editada: Jan
el 25 de En. de 2019
Stelios Fanourakis
el 25 de En. de 2019
Editada: Jan
el 25 de En. de 2019
Jan
el 25 de En. de 2019
@Stelios: I'm not sure if I can see what you call rulers. The posted image seems to be scaled. There are several grey dashs, but it is not clear, how they "indicate the height and width of the imaging window".
This sentence is not clear:
"My yellow marks say that I want scanning to start from the first black pixel (row of black pixels) until the first dash pixel (gray) and the same procedure starting from bottom up until the first gray (dash) pixel."
Does "first" mean horizontally or vertically? "first pixel (row of pixels)" is confusing - pixel or row of pixels?
Cropping does not cause any resampling. Why do you assume this? Cropping means just to crop the array.
- Is the posted image the real input you have? Do the image contain the yellow lines on the right side?
- What is is the wanted output? "Masking" means, that the output has the same array size as the inputs. Cropping means, that you crop out the area of interest - without any resampling.
- What is a unequivocal definition of the location you want to use? Something like:
Left top pixel: the pixel under the left lower corner of the blue rectangle
Left bottom pixel: same horizontal position, vertical position is ???
Right top pixel: ???
Right bottom pixel: is well defined then, when the area is a rectangle
Please try to use less words and more clarity. Actually 5 sentences are enough to define the problem. Post an input, the above definition and as bonus a handmade output. This will save time for you and for the readers.
Guillaume
el 25 de En. de 2019
Cropping will cause resampling.
No it won't. Cropping results in a smaller image. You just chop off the bits you don't want. Of course if you display that smaller image at with the same width and height as the original image, then the display will have to be scaled.
In any case, regardless of whether or not you crop the image, as far as I understand all you want to do is identify the left-right and top-down border of the part of the image you want to keep. Whether or not you just chop these borders or set them to black doesn't really matter. Either is trivial to do.
You still haven't clearly explained how to identify these borders. My understanding is that for top and bottom it's the first an last tick mark (outer or inner edge?). I've no idea what it is for the left and right border.
Again, what you describe has nothing to do with image segmentation and will not involve any scanning
Exporting the image from the ultrasound unit comes along with all those annotations
I would assume that the ultrasound unit would allow you to export the raw ultrasound, but maybe not. It's something I would explore. What you're exporting is the display, you're talking about not wanting any resampling but that screen capture is definitively a downsampled version of the raw image.
Stelios Fanourakis
el 25 de En. de 2019
Cropping to my experience causes resampling. So no cropping. I had bad experience cropping. Pixel size gets smaller.
You seem to be confusing cropping and resizing. cropping never changes the size of the pixels. Cropping is never a resampling operation. However, as said whether the final step is to crop or blank image border is not important.
the first pixel it finds is from the dash line of the horizontal ruler.
I cannot clearly see a horizontal ruler. The vertical ruler is better defined but some tick marks are poorly visible. The ruler is also not touching the edge of the right black border of your image so reliably locating these ticks marks is going to be the main difficulty. Note that the reason that all these tick marks are poorly visible (and that they don't all have the same size) is because your image is already downsampled. Badly! The fact that the image has been saved as jpeg also doesn't help as this creates its own artifacts (jpeg is a lossy format that particularly does not cope well with sharp transitions from black to white).
I want only the areas of the ruler to be visible
Can you draw a rectangle on the image clearly showing the area of the image you want to keep. That would make your explanation simpler.
By the way, does this have to be done programmatically. It would be easier if you selected interactively the area of the image you want to keep. That's trivial to implement in matlab.
Stelios Fanourakis
el 25 de En. de 2019
Stelios Fanourakis
el 25 de En. de 2019
Editada: Jan
el 26 de En. de 2019
Jan
el 26 de En. de 2019
@Stelios: You have posted 2 images. The first one contains 2 yellow bars, the second one a yellow rectangle. As far as I understand, the yellow elements are not part of the real data, but only inserted as an explanation, correctly? The upper yellow bar has no correlation to the yellow box, does it? The lower position of the yello box is determined by the upper limit of the 2 small lines (one consisting of about 3 pixels and the other of 2 pixels)? The Image contains a huge white border also? The image is saved as JPG with a lossy compression. This means, that it contains artefacts and no sharp edges. This will impede the detectiopn of certain coordinates massively.
You still did not explain exactly, what the inputs are and how the wanted positions can be recognized uniquely. There seems to be a confusion about the definition of "cropping": An image is a 3D array with the indices [1:X, 1:Y, 1:3]. Cropping means, that you cut out an array with the indices [x1:x2, y1:y2, 1:3]. This does neither do any downsampling and the size of pixels do not matter in any way.
My question for clarification is still open: How are these x1, x2, y1, y2 exactly defined?
Stelios Fanourakis
el 26 de En. de 2019
Stelios Fanourakis
el 26 de En. de 2019
Editada: Stelios Fanourakis
el 26 de En. de 2019
@Stelios: As far as I can see, you still did not answer, what your inputs are exactly. You have posted a JPEG file, which is compressed with lossy method, such that the file contains artifacts. This impedes the determination of the pixels of the ruler massively. A lossless file format would be ways better. In addition, this image contains huge white borders and you did not explain yet, if they are existing in the original files also (if files are the input at all). It is not clear, if you want to apply the procedure to one image manually or thousands of images automatically.
The text looks like the image is downsamples already: The fonts are slightly deformed. You have explained, that it is not downsampled, but it definitely looks like it is. The image you have posted here looks much better: Not scaled and without JPEG artifacts: https://www.mathworks.com/matlabcentral/answers/uploaded_files/200898/A1b.jpg . Why not using this images as input? Even the horizontal ruler is perfectly visible in opposite to the images you post here.
There seems to be a small O between the image and the vertical ruler. Did you mention this already?
An automatical masking of lossy JPEGs taken from scaled screenshots seems to be an unreliable and inaccurate method, which is not useful for scientific work, especially in the field of medicin.
Actually it should be easy to use a find command and the row, which contains the vertical ruler. But as long as it is not clear, if the original image contains this white border, and if a downsampling or lossy compressions blurrs the grey pixels of this ruler, suggesting specific code would be a crude guessing only.
I give up here. After 14 comments and some clear questions for clarifications, I do not know, what the inputs are and what you exactly want to achieve. I do not see, why you want a "masking", when then main part of the image is masked than and simply wastes space. Therefore I assume, that I cannot help you. Good luck.
Stelios Fanourakis
el 28 de En. de 2019
Editada: Stelios Fanourakis
el 28 de En. de 2019
Rik
el 28 de En. de 2019
Compare the image you have just posted with the image that is attached to the question itself. There is a difference in size. That makes it unclear what is actually the imput that you start with. You say you will be processing a lot of files. That makes it very important to know the boundary conditions of you data.
Your jpg inputs are lossy, which makes it difficult to find things that are easy for the human eye to find. jpg is not optimized for analysis, it is optimized for human viewing. All sharp edges (like the ticks, which are extremely important here) will get blurred.
I understand your frustration, but apparently your question is not clear enough, otherwise we could have given you an answer already. If you ignore direct questions ('which of the images you have attached is the actual start of your workflow') and then continue on to say that your question is clear is not helpful for anyone.
Jan has written several remarks in a quite long comment, but you hardly reply to them.
You want to find a mask that covers the ultrasound area, based on the depth and width indicators (the ticks at the border). That much is clear. What is not clear is what your exact input image is. Some of the images you have posted look like very lossy jpg files, others don't suffer as much from any downsampling. Some images you have posted have a white border, some have a red thin border, some lack either or both. Which of these is the input?
Stelios Fanourakis
el 28 de En. de 2019
Stelios Fanourakis
el 28 de En. de 2019
@Stelios: But due to the choice of a lossy and low quality JPEG compression and due to downsampling/re-scaling, there is no way to recognize pixels in the vertical ruler exactly and uniquely. I've collected the images you have posted yet and it is obvious, that each one would need another method to identify a certain pixel - if this is not made impossible by the bad choice of the image compression, rescaling, downsampling and adding of the border.
"Only to define the first and last points of the vertical ruler" - exactly this was made extremely hard, because you've posted very different inputs and the blurred contents does not allow to identify specific points. See this zoomed area of the right bottom ruler mark with increased contrast:

So which one is the wanted pixel?
Of course you can set some thresholds based on some expert knowledge and use AI to remove the JPEG artifacts. But it would be trivial, if you just use inputs without a lossy compression. Do you have any good reason to work with very noisy inputs? I'm convinced you have caused this noise by a repeated resampling and JPEG compression. Now the input images are trashy.
Guillaume
el 28 de En. de 2019
I just need Matlab to identify those two points. First and last dash of the vertical ruler. That's all!
This needs to be automated.
Yes, we understood that. But if you want something reliable we need to know exactly what we're working with. Because the solution and its complexity is going to depend on (amongst other things):
- Are these marks always in the same location in reference to the edges of the image. You've posted all sort of images where there is sometimes a white border, sometimes not. So, do we first have to identify that white border or not?
- Are these marks clearly defined or plagued by jpeg compression artifacts and sometimes downsampling (despite your protests you've shown us downsampled images, see Jan's answer)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Read, Write, and Modify Image en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




.bmp)
